常用命令之ls 详解

ls详解

罗列目录内容权限,列出文件的信息列表(默认为当前目录)。

这个命令是Linux操作系统使用频率最高的命令,没有之一。熟练掌握这个命令的常用参数,可以提高学习、工作效率,因此需要认真对待。

1. 常用选项

– -a,–all:显示当前目录下全部文件(常用)

[root@jingz ~]# ls -a   
..bash_history  .bashrc  .cshrc.lesshst  .viminfo  .xauthVB71h5..   .bash_logout   .cache   .dbus .local.xauth3F8Xbp
anaconda-ks.cfg  .bash_profile  .config  initial-setup-ks.cfg  .tcshrc   .xauth3fbnpT

-A, –almost-all:显示当前目录下的所有文件但是不包括.和..这两个目录

[root@jingz ~]# ls -A
anaconda-ks.cfg  .bash_profile  .config  initial-setup-ks.cfg  .tcshrc       .xauth3fbnpT
.bash_history    .bashrc        .cshrc   .lesshst              .viminfo      .xauthVB71h5
.bash_logout     .cache         .dbus    .local                .xauth3F8Xbp

-l: 用长格式显示非隐藏文件,列出长数数据串,包含文件的属性与权限等(常用)

[root@jingz ~]# ls -l
total 8
-rw-------. 1 root root 1706 Jul 24 18:31 anaconda-ks.cfg
-rw-------. 1 root root 1754 Jul 24 09:56 initial-setup-ks.cfg

–author:和-l选项一起使用,显示出每个文件的作者

[root@jingz ~]# ls -l --author
total 8
-rw-------. 1 root root root 1706 Jul 24 18:31 anaconda-ks.cfg
-rw-------. 1 root root root 1754 Jul 24 09:56 initial-setup-ks.cfg

-d, –directory:仅仅列出目录本身,而不列出目录内的文件数据(常用)

[root@jingz ~]# ls -d /etc
/etc

-f :直接列出结果,而不进行排序(ls 默认以文件名排序)
-F :根据文件、目录等信息给予附加数据结构,例如: * 代表可执行文件; / 代表目录; = 代表 socket文件;| 代表 FIFO文件

[root@jingz ~]# ls -F /
bin@   dev/  home/  lib64@  mnt/  proc/  run/   srv/  testdir/  usr/
boot/  etc/  lib@   media/  opt/  root/  sbin@  sys/  tmp/      var/

这个命令现在用的不多因为现在有了颜色高亮,可以通过不同颜色来判断目录,文件等等;

蓝色文件———-目录

白色文件———-一般性文件,如文本文件,配置文件,源码文件等

浅蓝色文件———-链接文件,主要是使用ln命令建立的文件

绿色文件———-可执行文件,可执行的程序

红色文件———–压缩文件或者包文件

-h ,将文件容量以人类易读的方式(例如GB,KB等)列出来(常用)

[root@jingz ~]# ls -hl
total 12K
-rw-r--r--. 1 root root   54 Jul 30 17:23 123
-rw-------. 1 root root 1.7K Jul 24 18:31 anaconda-ks.cfg
-rw-------. 1 root root 1.8K Jul 24 09:56 initial-setup-ks.cfg

-i ,列出inode号码(常用)

[root@jingz ~]# ls -i
104432133 123  104922027 anaconda-ks.cfg  104428540 initial-setup-ks.cfg

-n 列出UID和GID

[root@jingz ~]# ls -n
total 12
-rw-r--r--. 1 0 0   54 Jul 30 17:23 123
-rw-------. 1 0 0 1706 Jul 24 18:31 anaconda-ks.cfg
-rw-------. 1 0 0 1754 Jul 24 09:56 initial-setup-ks.cfg

–full-time 以完整时间模式(包含年、月、日、时、分、秒)输出

[root@jingz ~]# ls --full-time 
total 12
-rw-r--r--. 1 root root   54 2016-07-30 17:23:01.531177259 +0800 123
-rw-------. 1 root root 1706 2016-07-24 18:31:24.384061072 +0800 anaconda-ks.cfg
-rw-------. 1 root root 1754 2016-07-24 09:56:04.952024819 +0800 initial-setup-ks.cfg

-r 将结果反向输出,例如原来是由大到小,现在就由小到大
-R 连同子目录下面的所有非隐藏文件都显示出来
-S 以文件容量大小排序,而不用文件名排序
-t –time=(ctime|atime)按照时间排序,而不是文件名

2. 常用组合

ll 是一个别名,是代表ls -l的意思

[root@jingz ~]# ll
    total 12
    -rw-r--r--. 1 root root   54 Jul 30 17:23 123
    -rw-------. 1 root root 1706 Jul 24 18:31 anaconda-ks.cfg
    -rw-------. 1 root root 1754 Jul 24 09:56 initial-setup-ks.cfg

ls -ld 显示当前目录的详细信息

[root@jingz ~]# ll -d
dr-xr-x---. 6 root root 4096 Jul 30 17:23 .

ls -al 列出当前目录的所有文件的详细信息

[root@jingz ~]# ls -al
total 76
dr-xr-x---.  6 root root  4096 Jul 30 17:23 .
dr-xr-xr-x. 18 root root  4096 Jul 27 11:13 ..
-rw-r--r--.  1 root root    54 Jul 30 17:23 123
-rw-------.  1 root root  1706 Jul 24 18:31 anaconda-ks.cfg
-rw-------.  1 root root 10329 Jul 30 18:32 .bash_history

ls -al –full-time :列出当前文件所有的详细信息及准确时间

[root@jingz ~]# ls --full-time  -al 
total 76
dr-xr-x---.  6 root root  4096 2016-07-30 17:23:01.518177258 +0800 .
dr-xr-xr-x. 18 root root  4096 2016-07-27 11:13:51.466531634 +0800 ..
-rw-r--r--.  1 root root    54 2016-07-30 17:23:01.531177259 +0800 123
-rw-------.  1 root root  1706 2016-07-24 18:31:24.384061072 +0800 anaconda-ks.cfg
-rw-------.  1 root root 10329 2016-07-30 18:32:56.663329844 +0800 .bash_history

ll -ahS 用人类可读的格式由大到小列出所有文件

[root@jingz ~]# ll -aSh
total 76
total 76K
-rw-------.  1 root root  11K Jul 30 18:32 .bash_history
-rw-------.  1 root root 4.8K Jul 30 11:10 .viminfo

原创文章,作者:fighter,如若转载,请注明出处:http://www.178linux.com/26924

(0)
fighterfighter
上一篇 2016-08-02
下一篇 2016-08-02

相关推荐

  • 学习宣言

    书山有路勤为径,学海无涯苦作舟。学吧!!!

    Linux干货 2016-10-29
  • 马哥教育网络班N22期+第三周课程练习

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。    who | cut -d " " -f 1 | sort | uniq 2、取出最后登录到当前系统的用户的相关信息。    last | head -n 1  3、取出当前系统上被用户当作其默…

    Linux干货 2016-09-08
  • N26第三周

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。        who -i或-u 显示闲置时间, 若该用户在前一分钟之内有进行任何动作,将标示成"."号,如果该用户已超过24小时没有任何动作,则标示出"old"字符串   &n…

    Linux干货 2017-01-16
  • N26-第二周作业-邢岩(2)

     马哥门徒-N26-邢岩   我们接着说今天的分享,接着,我们来看看bash的工作特性之命令执行状态返回值和命令行展开所涉及的内容好了。    1.bash的基础特性之:命令的执行状态结果      bash通过状态返回值来输出此结果:       成功:0 …

    Linux干货 2017-02-10
  • 今天正式加入马帮开启我的学习Linux之路

    3月26日马哥教育30期开学仪式,终于见到了我们的马哥马永亮先生,同时马哥还有前大众点评架构师张Sir以及国内首批通过红帽授权认证讲师(RHCI)的老王给我们新生做了开学演讲。接着我们的宗华老师以及云珍老师对我们平时的学习以及生活做出了各种介绍与规定,还有我们同学之间也进行了相互自我介绍彼此熟悉….

    2018-03-26
  • grub启动

    grub: GRandUnified Bootloader(统一的引导模式分为3个阶段) grub 0.97: grub legacy grub 2.x: grub2 grub legacy: stage1: mbr stage1_5: mbr之后的扇区,让stage1中的bootloader能识别stage2所在的分区上的文件系统 stage2:磁盘分区(…

    Linux干货 2017-05-15