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

相关推荐

  • 路径操作&StringIO/BytesIO

    Edit 路径操作&StringIO/BytesIO 路径操作 路径操作模块: 3.4版本以前os.path模块 In [1]: from os import path In [2]: p = path.join(‘/etc’,’sysconfig’,’network’)#将字符…

    Linux干货 2017-10-30
  • N25第七周博客作业

    第七周博客作业 1、 创建一个10G分区,并格式为ext4文件系统; fdisk/dev/sdb à nàpàlast扇区:+10Gàwàpartx -a /dev/sdb   (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; mke2fs  -t ext4 -b 2…

    Linux干货 2017-02-20
  • 第二周作业

    第一、文件管理类命令     cp、mv、rm                  cp命令:copy 源文件;目标文件;     &nbsp…

    Linux干货 2016-12-12
  • N25-第六周总结 vim编辑器

    vim编辑器:         模式化的编辑器             基本模式:                     编辑模式,命令模式,输入模式,末行模…

    Linux干货 2017-02-15
  • 系统基础之用户,组管理作业题

    、创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser 1 2 3 [root@wen-7 ~]# useradd -u 1234 -g bin -G root,ftp&nbsp…

    Linux干货 2016-08-04
  • linux常见命令示例

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 ############################################################################# cp -ar /etc/skel/ /home/tuser1 [ro…

    Linux干货 2017-12-25