ls命令

ls命令

  ls是list files and directories的缩写,即列出目录中的文件和子目录。
  ls命令最简单的用法就是不加任何参数,执行后会列出当前目录下所有目录和文件的名称。

# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

  ls可以添加参数以显示更多的内容:
  显示内容包括隐藏文件、.(表示当前目录)和..(表示上一层目录):

# ls -a
. .. bin boot dev etc home lib lib64 media mnt opt proc .readahead root run sbin srv sys tmp usr var

显示内容包括隐藏文件,但是不包括.(表示当前目录)和..(表示上一层目录):

# ls -A
bin boot dev etc home lib lib64 media mnt opt proc .readahead root run sbin srv sys tmp usr var

  显示文件和目录的详细信息:

# ls -l
total 36
lrwxrwxrwx. 1 root root    7 Sep 15 19:26 bin -> usr/bin
dr-xr-xr-x. 4 root root 4096 Sep 15 19:35 boot
drwxr-xr-x. 19 root root 3020 Sep 21 21:59 dev
drwxr-xr-x. 102 root root 8192 Sep 21 21:59 etc
drwxr-xr-x. 3 root root 17 Sep 15 19:35 home
lrwxrwxrwx. 1 root root    7 Sep 15 19:26 lib -> usr/lib
lrwxrwxrwx. 1 root root    9 Sep 15 19:26 lib64 -> usr/lib64
drwxr-xr-x. 2 root root    6 Aug 12 2015 media
drwxr-xr-x. 2 root root    6 Aug 12 2015 mnt
drwxr-xr-x. 3 root root 15 Sep 15 19:32 opt
dr-xr-xr-x. 149 root root    0 Sep 21 21:59 proc
dr-xr-x---+ 14 root root 4096 Sep 20 11:46 root
drwxr-xr-x. 30 root root 960 Sep 21 22:00 run
lrwxrwxrwx. 1 root root    8 Sep 15 19:26 sbin -> usr/sbin
drwxr-xr-x. 2 root root    6 Aug 12 2015 srv
dr-xr-xr-x. 13 root root    0 Sep 21 21:59 sys
drwxrwxrwt. 9 root root 4096 Sep 21 21:59 tmp
drwxr-xr-x. 13 root root 4096 Sep 15 19:26 usr
drwxr-xr-x. 21 root root 4096 Sep 21 21:59 var

  可以按修改的日期时间进行排序(由近到远)输出:

# ls -tl
total 36
drwxr-xr-x. 30 root root 960 Sep 21 22:00 run
drwxrwxrwt. 9 root root 4096 Sep 21 21:59 tmp
drwxr-xr-x. 102 root root 8192 Sep 21 21:59 etc
drwxr-xr-x. 19 root root 3020 Sep 21 21:59 dev
dr-xr-xr-x. 13 root root    0 Sep 21 21:59 sys
drwxr-xr-x. 21 root root 4096 Sep 21 21:59 var
dr-xr-xr-x. 149 root root    0 Sep 21 21:59 proc
dr-xr-x---+ 14 root root 4096 Sep 20 11:46 root
dr-xr-xr-x. 4 root root 4096 Sep 15 19:35 boot
drwxr-xr-x. 3 root root 17 Sep 15 19:35 home
drwxr-xr-x. 3 root root 15 Sep 15 19:32 opt
drwxr-xr-x. 13 root root 4096 Sep 15 19:26 usr
lrwxrwxrwx. 1 root root    8 Sep 15 19:26 sbin -> usr/sbin
lrwxrwxrwx. 1 root root    7 Sep 15 19:26 lib -> usr/lib
lrwxrwxrwx. 1 root root    9 Sep 15 19:26 lib64 -> usr/lib64
lrwxrwxrwx. 1 root root    7 Sep 15 19:26 bin -> usr/bin
drwxr-xr-x. 2 root root    6 Aug 12 2015 media
drwxr-xr-x. 2 root root    6 Aug 12 2015 mnt
drwxr-xr-x. 2 root root    6 Aug 12 2015 srv

  可以按修改的日期时间进行排序(由远到近)输出:

[root@localhost /]# ls -rtl
total 36
drwxr-xr-x. 2 root root    6 Aug 12 2015 srv
drwxr-xr-x. 2 root root    6 Aug 12 2015 mnt
drwxr-xr-x. 2 root root    6 Aug 12 2015 media
lrwxrwxrwx. 1 root root    7 Sep 15 19:26 bin -> usr/bin
lrwxrwxrwx. 1 root root    9 Sep 15 19:26 lib64 -> usr/lib64
lrwxrwxrwx. 1 root root    7 Sep 15 19:26 lib -> usr/lib
lrwxrwxrwx. 1 root root    8 Sep 15 19:26 sbin -> usr/sbin
drwxr-xr-x. 13 root root 4096 Sep 15 19:26 usr
drwxr-xr-x. 3 root root 15 Sep 15 19:32 opt
drwxr-xr-x. 3 root root 17 Sep 15 19:35 home
dr-xr-xr-x. 4 root root 4096 Sep 15 19:35 boot
dr-xr-x---+ 14 root root 4096 Sep 20 11:46 root
dr-xr-xr-x. 149 root root    0 Sep 21 21:59 proc
drwxr-xr-x. 21 root root 4096 Sep 21 21:59 var
dr-xr-xr-x. 13 root root    0 Sep 21 21:59 sys
drwxr-xr-x. 19 root root 3020 Sep 21 21:59 dev
drwxr-xr-x. 102 root root 8192 Sep 21 21:59 etc
drwxrwxrwt. 9 root root 4096 Sep 21 21:59 tmp
drwxr-xr-x. 30 root root 960 Sep 21 22:00 run

  除了可以显示当前目录外,也可以显示指定目录的内容。
  显示指定目录/var的内容:

# ls /var
account adm cache crash db empty games gopher kerberos lib local lock log mail nis opt preserve run spool tmp www yp