ls应该是我们最熟悉的指令之一,通常进入命令行,少不了就要ls一下。
虽然它是一个很基本很常用的命令,不过它的功能也很丰富,熟练使用它可以更加便捷我们看我们想要看到的文件信息。
本文ls介绍基于CentOS7.2环境,后面的实验均在此环境下实现。
ls命令介绍
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 
 [root@localhost ~]# man ls  LS(1)                            User Commands                           LS(1)     NAME         ls - list directory contents     SYNOPSIS         ls [OPTION]... [FILE]...     DESCRIPTION         List  information  about  the FILEs (the current directory by default).         Sort entries alphabetically if none of -cftuvSUX nor --sort  is  speci‐         fied.            Mandatory  arguments  to  long  options are mandatory for short options         too.            -a, --all                do not ignore entries starting with .         -A, --almost-all                do not list implied . and ..         -d, --directory                list directories themselves, not their contents         -h, --human-readable                with -l, print sizes in human readable format (e.g., 1K 234M 2G)         -i, --inode                print the index number of each file        -l     use a long listing format        -r, --reverse                reverse order while sorting         -R, --recursive                list subdirectories recursively         -S     sort by file size         -t     sort by modification time, newest first         -u     with  -lt:  sort by, and show, access time; with -l: show access                time and sort by name; otherwise: sort by access time
以上的内容有所省略,本文只截取常用到的11个选项做详细说明。
-a 显示所有内容,包括以.开头的隐藏文件
 1 2 3 4 5 
 [root@localhost ~]# ls -a /root  .                .bash_logout   .config  .esd_auth             .local       公共  文档  ..               .bash_profile  .cshrc   .ICEauthority         .mozilla     模板  下载  anaconda-ks.cfg  .bashrc        CST      initial-setup-ks.cfg  .tcshrc      视频  音乐  .bash_history    .cache         .dbus    .lesshst              .Xauthority  图片  桌面
-A 显示所有内容,但不包括.和..文件,显示以.开头的隐藏文件
 1 2 3 4 5 
 [root@localhost ~]# ls -A /root/  anaconda-ks.cfg  .bashrc  CST            initial-setup-ks.cfg  .tcshrc      视频  音乐  .bash_history    .cache   .dbus          .lesshst              .Xauthority  图片  桌面  .bash_logout     .config  .esd_auth      .local                公共         文档 

