常用命令之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

相关推荐

  • tab键 history 命令的相关巧用

    Tab键的妙用       1.command没有完全输入时: 点击tab,如果能唯一匹配到命令,则直接补全,否则需要点击两下tab来显示能够匹配到的命令。                2./2tab : 显…

    2017-02-18
  • LVS详解

    概述     LVS是工作在4层的负载均衡调度器,可根据请求报文的目标IP和目标协议及端口,根据指定的调度算法,将请求调度转发至某RealServer,本篇就针对LVS的原理,配置和使用进行简单介绍,具体包含:     1、LVS的四种类型的介绍   &nbs…

    Linux干货 2016-10-27
  • 马哥教育网络班第22期+第14周作业

    week14: 系统的INPUT和OUTPUT默认策略为DROP; 1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒; web服务器包含了admin字符串的页面不允许访问;web服务器仅允许响应报文离开本机; 2、在工作时间,即周一到周五的8:30-18:00,开放本机的ftp服务给172.16.0.0网络中的主机访问; 数据…

    Linux干货 2016-12-12
  • 8.10 shell scripts 作业

    1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 [root@CentOs6 bin]# systeminfo.sh        Hostname:&n…

    Linux干货 2016-08-12
  • 数据库的备份和恢复

    数据库的备份和恢复 一 (理论篇)、数据库备份与恢复基础 1、数据库的备份与恢复 备份:存储的数据副本; 原始数据:持续改变; 恢复:把副本应用到线上系统; 仅能恢复至备份操作时刻的数据状态; 时间点恢复: binary logs; 2、为什么备份? 灾难恢复: 硬件故障(冗余)、软件故障(bug)、自然灾害、黑客攻击、误操作、…&nb…

    2016-11-22
  • 网络基础笔记

    网络管理笔记 1. 网络概念:     一组网络设备或计算机,通过无形的规则链接起来的体系!    2. 应用程序种类:     (1)批处理应用程序:            FTP、TFTP、库存更新    &nbsp…

    Linux干货 2017-03-16