Linux文件是以根为起始点,在Linux / 代表起始也就是根,因为Linux是倒树根你可以直接理解成一棵树倒着,先是树根,然后树干,再然后树枝最后到达树叶比如:/home/user/1.txt
我们先看下文件的路径全貌
[root@localhost user]# ls /home/user/1.txt /home/user/1.txt
一、常用的文件及目录的管理命令吧!
ls:列出文件
[root@localhost user]# ls1.txt
cd:切换目录比如
[root@localhost user]# pwd/home/user[root@localhost user]# cd /usr/local/[root@localhost local]# pwd/usr/local
pwd:显示当前目录位置
[root@localhost user]# pwd/home/user
mkdir:创建目录
[root@localhost user]# ls1.txt[root@localhost user]# mkdir test[root@localhost user]# ll总用量 4-rw-r--r-- 1 root root 0 9月 22 22:06 1.txtdrwxr-xr-x 2 root root 4096 9月 22 22:10 test
cp:复制文件或目录
[root@localhost user]# ls test/[root@localhost user]# cp 1.txt test/[root@localhost user]# ls test/1.txt
mv:剪切或者重命名
[root@localhost user]# ls test/1.txt[root@localhost user]# ls1.txt test[root@localhost user]# mv 1.txt 2.txt[root@localhost user]# ls2.txt test[root@localhost user]# mv 2.txt test/[root@localhost user]# lstest[root@localhost user]# ls test/1.txt 2.txt
rm:删除文件或目录
[root@localhost user]# ls test/1.txt 2.txt[root@localhost user]# rm test/1.txt rm:是否删除普通空文件 "test/1.txt"?y[root@localhost user]# ls test/2.txt[root@localhost user]# rm -r test/rm:是否进入目录"test"? yrm:是否删除普通空文件 "test/2.txt"?yrm:是否删除目录 "test"?y[root@localhost user]# ls[root@localhost user]#
二、文件查看
cat:查看文件内容,从第一行开始
[root@localhost user]# cat 1.txt The is Test page.The is Test page2.The is Test page3.
tac:查看内容文件,从最后一行开始
[root@localhost user]# tac 1.txt The is Test page3.The is Test page2.The is Test page.
nl:查看内容文件,显示的时候顺带显示行
[root@localhost user]# nl 1.txt 1 The is Test page. 2 The is Test page2. 3 The is Test page3.
more:查看内容,分屏显示,该命令在文件内容较多的时候使用效果直观,省略了部分内容~注意看--More--(25%)一个屏幕显示了四分之一的内容
[root@localhost user]# more /etc/man.config ## Generated automatically from man.conf.in by the# configure script....# The keyword FHS will cause this behaviour (and overrides FSSTND).# Explicitly given catdirs override.--More--(25%)
less:类似more只不过less可以往上翻
head:可以查看前几行
[root@localhost user]# head /etc/man.config ## Generated automatically from man.conf.in by the# configure script.## man.conf from man-1.6f## For more information about this file, see the man pages man(1)# and man.conf(5).## This file is read by man to configure the default manpath (also used
tail:只看最后几行(默认10行)
[root@localhost user]# tail /etc/man.config ## Enable/disable makewhatis database cron updates.# If MAKEWHATISDBUPDATES variable is uncommented# and set to n or N, cron scripts # /etc/cron.daily/makewhatis.cron# /etc/cron.weekly/makewhatis.cron# will not update makewhatis database.# Otherwise the database will be updated.# #MAKEWHATISDBUPDATES n
当然也可以使用head与tail组合查看特定的行,比如我只想看1.txt的第二行:
[root@localhost user]# cat 1.txt The is Test page.The is Test page2.The is Test page3.[root@localhost user]# head -2 1.txt | tail -1The is Test page2.[root@localhost user]#
至此简单的文件及目录的管理查看命令基本就OK拉
欢迎大家关注 459479177QQ群