常用命令之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 10:55
下一篇 2016-08-02 10:55

相关推荐

  • 初识Linux-即使是997也不能停止学习

    1.计算机的组成及其功能:    从1946年第一台通用计算机ENIAC诞生至今,几乎所有的计算机系统都是建立在冯诺依曼体系结构上的。那么何为冯诺依曼体系结构? 冯诺依曼体系结构:        控制器:是整个计算机的中枢,负责计算机的整体调度工作,将指令从存储器中取出,并对指令进行解释执行。 &n…

    Linux干货 2016-10-29
  • N27_第一周作业

    一、描述计算机的组成及其功能 计算机由CPU、内存、输入设备和输出设备组成。 CPU:运算器、控制器、寄存器、缓存 *运算器:进行数字运算和逻辑运算。 *控制器: A、从内存中取出一条指令,并指出下一条指令在内存中的位置; B、对指令进行译码或测试,并产生相应的操作控制信号; C、控制并控制CPU、内存和输入/输出设备之间数据流动的方向。 *寄存器:暂存指令…

    Linux干货 2017-09-04
  • linux命令简单应用

    创建/tmp目录下的:a_c, a_d, b_c, b_d touch /tmp/{a,b}_{c,d} [root@bogon ~]# tree /tmp /tmp |– a_c |– a_d |– b_c |– b_d 创建/tmp/mylinux目录下的: mylinux/ ├── bin ├── boo…

    Linux干货 2016-11-06
  • 任务计划使用方法

    概述     任务计划其实就是针对未来的某一刻或者是某一周期内设置要执行的工作;     任务计划分为两种:         1、一次性任务:在指定的未来的某个时间点仅执行一次任务;  &n…

    Linux干货 2015-03-26
  • N25-第三周作业

      alias NAME='COMMAND'           定义命令的别名—对当前用户有效  un为解除别名 Which   查看命令别名 Whereis    查看程序的文档和源码路径(-b &nbs…

    Linux干货 2016-12-18
  • Nginx常用配置详解

    Nginx常用配置详解(一) 本文依照nginx官方站点文档介绍常用的nginx各种常用配置,未经过校对,如有错误还望海涵。 Nginx配置通用语法 Nginx最基本的配置语法 配置项名 配置项值1 [配置项值2 ….]; 配置项名位于行首,配置项值与配置项名之间用空格隔开,多个配置项值之间也用空格隔开,每行配置结尾必须加上分号。 #配置项名 配置项值1…

    Linux干货 2017-06-20