• ls命令详解


    返回基础命令目录页

    ls命令
    用来显示目标列表,在Linux中是使用率较高的命令。ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件。

    语法
    ls(选项)(参数)

    常用组合

    [1]查看文件详情:ls -l 或 ll
    [2]增强对文件大小易读性,以人类可读的形式显示文件大小: ls -lh
    [3]对文件或者目录进行从大到小的排序: ls -lhs
    [4]查看当前目录下的所有文件或者目录,包括隐藏文件: ls -la
    [5]只查看当前目录下的目录文件: ls -d .
    [6]按照时间顺序查看,从上到倒下时间越来越近: ls -ltr
    [7]查看文件在对应的inode信息:ls -li


    实例
    -a:显示所有档案及目录(ls内定将档案名或目录名称为“.”的视为影藏,不会列出);
    [root@lb02 ~]# ls -a
    .   anaconda-ks.cfg  .bash_logout   .bashrc      .cshrc  .ssh     .viminfo
    ..  .bash_history    .bash_profile  bootime.svg  .pki    .tcshrc
    -A:显示除影藏文件“.”和“..”以外的所有文件列表;
    [root@lb02 ~]# ls -A
    anaconda-ks.cfg  .bash_history  .bash_logout  .bash_profile  .bashrc  bootime.svg  .cshrc  .pki  .ssh  .tcshrc  .viminfo
    -C:多列显示输出结果。这是默认选项;
    -l:与“-C”选项功能相反,所有输出信息用单列格式输出,不输出为多列;
    [root@lb02 ~]# ls -1
    anaconda-ks.cfg
    bootime.svg
    -F:在每个输出项后追加文件的类型标识符,具体含义:“*”表示具有可执行权限的普通文件,“/”表示目录,“@”表示符号链接,“|”表示命令管道FIFO,“=”表示sockets套接字。当文件为普通文件时,不输出任何标识符;
    [root@lb02 ~]# ll
    total 8
    -rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh
    -rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfg
    drwxr-xr-x  2 root root    6 Feb 21 06:44 mydir
    [root@lb02 ~]# ls -F
    1.sh*  anaconda-ks.cfg  mydir/
    -b:将可输出的字符以反斜线“”加字符编码的方式输出;
    -c:与“-lt”选项连用时,按照文件状态时间排序输出目录内容,排序的依据是文件的索引节点中的ctime字段。与“-l”选项连用时,则排序的一句是文件的状态改变时间;
    [root@lb02 ~]# stat 1.sh mydir/ anaconda-ks.cfg 
      File: ‘1.sh’
    Change: 2018-02-21 06:44:09.172203419 -0500
      File: ‘mydir/’
    Change: 2018-02-21 06:44:46.476170254 -0500
      File: ‘anaconda-ks.cfg’
    Change: 2017-11-12 22:26:50.173018643 -0500
    [root@lb02 ~]# ls -c
    mydir  1.sh  anaconda-ks.cfg  #按照ctime排序
    -d:仅显示目录名,而不显示目录下的内容列表。显示符号链接文件本身,而不显示其所指向的目录列表;
    [root@lb02 ~]# ls -ld .
    dr-xr-x---. 5 root root 200 Feb 21 06:58 .
    -f:此参数的效果和同时指定“aU”参数相同,并关闭“lst”参数的效果;
    [root@lb02 ~]# ls -f
    .   .bash_logout   .bashrc  .tcshrc          .bash_history  .pki  .viminfo
    ..  .bash_profile  .cshrc   anaconda-ks.cfg  .ssh           1.sh  mydir
    [root@lb02 ~]# ls -aU
    .   .bash_logout   .bashrc  .tcshrc          .bash_history  .pki  .viminfo
    ..  .bash_profile  .cshrc   anaconda-ks.cfg  .ssh           1.sh  mydir
    [root@lb02 ~]# ls -lst
    total 8  
    0 drwxr-xr-x  2 root root    6 Feb 21 06:44 mydir
    4 -rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh
    4 -rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfg
    -i:显示文件索引节点号(inode)。一个索引节点代表一个文件;
    [root@lb02 ~]# ls -i *
    134435243 1.sh  134318146 anaconda-ks.cfg
    
    mydir:
    --file-type:与“-F”选项的功能相同,但是不显示“*”;
    [root@lb02 ~]# ls --file-type
    1.sh  anaconda-ks.cfg  mydir/
    -k:以KB(千字节)为单位显示文件大小;
    -l:以长格式显示目录下的内容列表。输出的信息从左到右依次包括文件名,文件类型、权限模式、硬连接数、所有者、组、文件大小和文件的最后修改时间等;
    [root@lb02 ~]# ls -l
    total 8
    -rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh
    -m:用“,”号区隔每个文件和目录的名称;
    [root@lb02 ~]# ls -m
    1.sh, anaconda-ks.cfg, mydir
    -n:以用户识别码和群组识别码替代其名称;
    [root@lb02 ~]# ls -n
    total 8
    -rwxr-xr-x  1 0 0    9 Feb 21 06:43 1.sh   ##uid 和gid显示
    -rw-------. 1 0 0 1627 Nov 12 22:26 anaconda-ks.cfg
    -r:以文件名反序排列并输出目录内容列表;
    [root@lb02 ~]# ls -lt
    total 8
    drwxr-xr-x  2 root root    6 Feb 21 06:44 mydir
    -rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh
    -rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfg
    [root@lb02 ~]# ls -ltr                                  #-t默认按照修改时间Mtime,-r逆序
    total 8
    -rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfg    
    -rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh
    drwxr-xr-x  2 root root    6 Feb 21 06:44 mydir
    -s:显示文件和目录的大小,以区块为单位;
    [root@lb02 ~]# ls -s
    total 8
    4 1.sh  4 anaconda-ks.cfg  0 mydir
    -t:用文件和目录的更改时间排序;
    [root@lb02 ~]# ls -lt
    total 8
    drwxr-xr-x  2 root root    6 Feb 21 06:44 mydir    #默认显示修改时间 
    -rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh
    -rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfg
    -L:如果遇到性质为符号链接的文件或目录,直接列出该链接所指向的原始文件或目录;
    -R:递归处理,将指定目录下的所有文件及子目录一并处理;
    [root@lb02 ~]# ls -R
    .:
    1.sh  anaconda-ks.cfg  mydir
    
    ./mydir:
    childir  myfile
    
    ./mydir/childir:
    my.txt
    --full-time:列出完整的日期与时间;
    [root@lb02 ~]# ls --full-time 
    total 8
    -rwxr-xr-x  1 root root    9 2018-02-21 06:43:41.248479699 -0500 1.sh
    -rw-------. 1 root root 1627 2017-11-12 22:26:50.173018643 -0500 anaconda-ks.cfg
    drwxr-xr-x  3 root root   35 2018-02-21 07:36:08.614123920 -0500 mydir
    --color[=WHEN]:使用不同的颜色高亮显示不同类型的。
    [root@lb02 ~]# alias ls   
    alias ls='ls --color=auto'   #别名默认就有

     参考:http://man.linuxde.net/ls



  • 相关阅读:
    memwatch使用简化
    memwatch检测内存泄露
    mtrace检测内存泄露
    2.14 环境变量及参数
    设计模式[索引]
    二叉树遍历
    AppCan 双击返回按钮退出应用
    MySQL语句相关经验总结
    mysql连接失败或出现“Too many connections”错误
    让IE的Button自适应文字宽度兼容
  • 原文地址:https://www.cnblogs.com/machangwei-8/p/8457372.html
Copyright © 2020-2023  润新知