pwd的功能显示当前工作目录。当用户登录系统之后在默认情况下, 进入自己的主目录。可以使用pwd来查看当前的工作目录:
pwd /home/lidq
可见,当前工作目录为lidq用户的主目录/home/lidq
cd命令的功能是切换当前工作目录。这一个非常有用的命令,在Linux下工作使用的最多的就是这个cd命令。它的参数就是想要切换的目录。可以是绝对路径,以/开头表示这个目标目录是从根目录开始的:
pwd /home/lidq cd /usr/bin pwd /usr/bin
也可以相对路径,不以/开头,表示在当前目录下的子目录,多级目录之间要使用/连接:
pwd /home/lidq cd Documents/books pwd /home/lidq/Documents/books
在/home/lidq这个工作目录下,进入其下的Documents/books目录,即:/home/lidq/Documents/books。另外cd命令在使用相对路径时,还可以使用“.”和“..”。“.”代表当前目录。“..”代表上一级目录。比如:
pwd /home/lidq cd ./Documents pwd /home/lidq/Documents cd ../Music pwd /home/lidq/Music
在进入/home/lidq/Documents之后,使用cd ../Music表示先进入当前当前目录的上一级目录/home/lidq再进入它的Music目录,即:/home/lidq/Music。
cd ~:直接进入当前用户的主目录:
pwd /usr/bin cd ~ pwd /home/lidq
cd -:进入上一次进入的目录:
pwd /home/lidq cd /usr/bin pwd /usr/bin cd - pwd /home/lidq cd - pwd /usr/bin
ls的功能是显示当前目录下的文件列表。
ls Desktop Downloads Pictures Public Videos Documents Music Templates
ls也是非常常用的一个命令,它有很多参数:
-a:显示全部文件,包括以.开头的隐藏文件:
ls -a . .. .bash_history .bash_logout .bash_profile .bashrc Desktop Documents Downloads
-A:不包括“.”和“..”:
ls -A .bash_history .bash_logout .bash_profile .bashrc Desktop Documents Downloads
-s:s是size的缩写,显示文件的大小:
ls -s total 160 4 background 40 Selection_001.png 8 switch_button_off.xcf 4 icon 104 Selection_003.png
-S:S是sort的缩写,按文件大小排序:
ls -sS total 160 104 Selection_003.png 8 switch_button_off.xcf 4 icon 40 Selection_001.png 4 background
-l:使用长列表格式,也就是表示文件的详细信息。ls -l常常被重定义为ll命令,也就是说使用ll命令相当于使用ls -l:
ls -l total 160 drwxrwxr-x. 2 lidq lidq 4096 Feb 28 16:23 background drwxrwxr-x. 2 lidq lidq 4096 Feb 9 10:07 icon -rw-rw-r--. 1 lidq lidq 40558 Mar 16 13:36 Selection_001.png -rw-rw-r--. 1 lidq lidq 104057 Mar 23 10:08 Selection_003.png -rw-rw-r--. 1 lidq lidq 5500 Mar 25 16:04 switch_button_off.xcf
-h:h是human的缩写,表示采用更人性化的、人类可读的方式来显示。比如上面例子中总大小和各个文件的大小为160、4096、40558和104057。如果采用-h参数,其结果为:
ls -sh total 160K 102K Selection_003.png 8.0K switch_button_off.xcf 4.0K icon 40K Selection_001.png 4.0K background ls -lh total 160K drwxrwxr-x. 2 lidq lidq 4.0K Feb 28 16:23 background drwxrwxr-x. 2 lidq lidq 4.0K Feb 9 10:07 icon -rw-rw-r--. 1 lidq lidq 40K Mar 16 13:36 Selection_001.png -rw-rw-r--. 1 lidq lidq 102K Mar 23 10:08 Selection_003.png -rw-rw-r--. 1 lidq lidq 5.4K Mar 25 16:04 switch_button_off.xcf
总大小和各个文件的大小为160k、4.0k、40k、102k。可见显示方式更加人性化,增加了结果信息的可读性。
Copyright © 2015-2023 问渠网 辽ICP备15013245号