ls命令是最常用的命令,用于查看当前或指定目录下的文件和文件夹列表,包括属性、排序。

-a 查看包括隐藏在内的所有文件和文件夹列表。

    [root@Centos ~]# ls -a

    .       100M.data     

    ..      1kfile.dat    

-A 类似于a,但不显示.和..这两个特殊的文件夹

    [root@Centos ~]# ls -A

    0k          1Mfile         

    0kfile      anaconda-ks.cfg

-B 忽略文件名以~开头的文件或文件夹(~开头多出现于backup文件、文件夹)

    [root@Centos ~]# ls

    0k      100M.data   1Mfile           install.log         test~

    [root@Centos ~]# ls -B

    0k      100M.data   1Mfile           install.log         testparm.result

-c 当仅配合-l使用时,显示ctime(Change time),并按照文件名排序

    当配合-lt,则显示并按照ctime排序

    [root@Centos ~]# ls -lc

    total 103600

    -rw-r--r--. 1 root root         4 Feb 12 18:57 0k

    -rw-r--r--. 1 root root         0 Feb  9 18:54 0kfile

    -rw-r--r--. 1 root root 104857600 Feb  9 18:59 100M.data

    -rw-r--r--. 1 root root      1024 Feb  9 18:25 1kfile.dat

    -rw-r--r--. 1 root root   1048576 Feb  9 18:50 1Mfile

    -rw-------. 1 root root      1211 Jan  2 01:25 anaconda-ks.cfg

    -rw-r--r--. 1 root root     27312 Jan  2 01:25 install.log

    -rw-r--r--. 1 root root      7572 Jan  2 01:25 install.log.syslog

    -rw-r--r--. 1 root root         0 Feb 12 19:58 test~

    -rw-r--r--. 1 root root     17746 Jan  3 18:37 testparm.result

    [root@Centos ~]# ls -ltc

    total 103600

    -rw-r--r--. 1 root root         0 Feb 12 19:58 test~

    -rw-r--r--. 1 root root         4 Feb 12 18:57 0k

    -rw-r--r--. 1 root root 104857600 Feb  9 18:59 100M.data

    -rw-r--r--. 1 root root         0 Feb  9 18:54 0kfile

    -rw-r--r--. 1 root root   1048576 Feb  9 18:50 1Mfile

    -rw-r--r--. 1 root root      1024 Feb  9 18:25 1kfile.dat

    -rw-r--r--. 1 root root     17746 Jan  3 18:37 testparm.result

    -rw-------. 1 root root      1211 Jan  2 01:25 anaconda-ks.cfg

    -rw-r--r--. 1 root root     27312 Jan  2 01:25 install.log

    -rw-r--r--. 1 root root      7572 Jan  2 01:25 install.log.syslog

-C 按列来显示文件、文件夹列表

-d 配合-l仅显示目录的信息,如果后面没有指定任何目录,则显示当前目录的

-f 不进行任何排序,并显示所有文件、文件夹,包括隐藏的。

-F 给不同类型的文件、文件夹结尾加上特殊符号(*/=>@|

    =号代表socket文件

    [root@Centos dev]# ll -F log

    srw-rw-rw-. 1 root root 0 Feb 12 17:35 log=

    [root@Centos dev]# file log

    log: socket

    *号代表具有执行权限的文件(文件夹不算)

    [root@Centos dev]# ll -F /usr/bin/

    -rwxr-xr-x. 1 root root       9056 Jun 22  2012 yum-builddep*


    /号代表文件夹

    drwxr-xr-x.  2 root root   4096 Nov 23  2013 statetab.d/


--time-style=<样式> 显示的时间按指定的样式显示。样式包含如下:

    long-iso

        [root@Centos ~]# ls -l --time-style=long-iso

        total 103600

        -rw-r--r--. 1 root root         4 2016-02-12 18:57 0k

        -rw-r--r--. 1 root root         0 2016-02-09 18:54 0kfile

    full-iso

        [root@Centos ~]# ls -l --time-style=full-iso

    total 103600

        -rw-r--r--. 1 root root         4 2016-02-12 18:57:37.000000000 +0800 0k

        -rw-r--r--. 1 root root         0 2016-02-09 18:54:22.000000000 +0800 0kfile

    iso

        [root@Centos ~]# ls -l --time-style=iso

        total 103600

        -rw-r--r--. 1 root root         4 02-12 18:57 0k

        -rw-r--r--. 1 root root         0 02-09 18:54 0kfile

    locale

        [root@Centos ~]# ls -l --time-style=locale

        total 103600

        -rw-r--r--. 1 root root         4 Feb 12 18:57 0k

        -rw-r--r--. 1 root root         0 Feb  9 18:54 0kfile

    自定义

        [root@Centos ~]# ls -l --time-style=+'%Y-%m-%d' 

        total 103600

        -rw-r--r--. 1 root root         4 2016-02-12 0k

        -rw-r--r--. 1 root root         0 2016-02-09 0kfile

按照文件体积来排序

    -S 默认从大到小排序,如果需要反转,可配合-r参数

 

显示不同的时间

    --time=<time type>,time type有atime、ctime,需要配合-l使用,如果不使用该参数,默认显示mtime

    

按不同属性来排序

    --sort=WORD

              sort by WORD instead of name: none -U, extension -X,

              size -S, time -t, version -v

              WORD可以是size、time、version,如果是time,则需配合--time参数

    [root@vmtest ~]# ll -t --time-style=long-iso  #按照mtime排序,从新到旧,显示的样式为long-iso

    -rw-r--r--. 1 root root      112 2016-01-16 10:59 fun.sh

    -rw-r-xr--+ 1 root root        0 2016-01-11 22:18 testfile

    -rwx------. 1 root root      171 2016-01-10 20:20 KickUser.sh

    [root@vmtest ~]# ll --sort=time --time=ctime --time-style=long-iso   #详写,按照时间从新到旧来排序、时间的类型是ctime(Change Time)、显示的时间样式为long-iso

    -rw-r--r--. 1 root root   111016 2015-10-09 23:26 httpd.txt

    -rw-r--r--. 1 root root     1377 2015-10-04 11:28 netstat.after

    -rw-r--r--. 1 root root      843 2015-10-04 11:26 netstat.before