博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ls命令详解
阅读量:7214 次
发布时间:2019-06-29

本文共 4126 字,大约阅读时间需要 13 分钟。

ls命令用来显示目标列表,在Linux中是使用率较高的命令。ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件。 语法
ls(选项)(参数)
常用组合

[1]查看文件详情:ls -l 或 ll

[2]增强对文件大小易读性,以人类可读的形式显示文件大小: ls -lh
[3]对文件或者目录进行从大到小的排序: ls -lhs
[4]查看当前目录下的所有文件或者目录,包括隐藏文件: ls -la
[5]只查看当前目录下的目录文件: ls -d .
[6]按照时间顺序查看,从上到倒下时间越来越近: ls -ltr
[7]查看文件在对应的inode信息:ls -li

实例 -a:显示所有档案及目录(ls内定将档案名或目录名称为“.”的视为影藏,不会列出);
[root@lb02 ~]# ls -a.   anaconda-ks.cfg  .bash_logout   .bashrc      .cshrc  .ssh     .viminfo..  .bash_history    .bash_profile  bootime.svg  .pki    .tcshrc
-A:显示除影藏文件“.”和“..”以外的所有文件列表;
[root@lb02 ~]# ls -Aanaconda-ks.cfg  .bash_history  .bash_logout  .bash_profile  .bashrc  bootime.svg  .cshrc  .pki  .ssh  .tcshrc  .viminfo
-C:多列显示输出结果。这是默认选项;-l:与“-C”选项功能相反,所有输出信息用单列格式输出,不输出为多列;
[root@lb02 ~]# ls -1anaconda-ks.cfgbootime.svg
-F:在每个输出项后追加文件的类型标识符,具体含义:“*”表示具有可执行权限的普通文件,“/”表示目录,“@”表示符号链接,“|”表示命令管道FIFO,“=”表示sockets套接字。当文件为普通文件时,不输出任何标识符;
[root@lb02 ~]# lltotal 8-rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh-rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfgdrwxr-xr-x  2 root root    6 Feb 21 06:44 mydir[root@lb02 ~]# ls -F1.sh*  anaconda-ks.cfg  mydir/
-b:将文件中的不可输出的字符以反斜线“”加字符编码的方式输出; -c:与“-lt”选项连用时,按照文件状态时间排序输出目录内容,排序的依据是文件的索引节点中的ctime字段。与“-l”选项连用时,则排序的一句是文件的状态改变时间;
[root@lb02 ~]# stat 1.sh mydir/ anaconda-ks.cfg   File: ‘1.sh’Change: 2018-02-21 06:44:09.172203419 -0500  File: ‘mydir/’Change: 2018-02-21 06:44:46.476170254 -0500  File: ‘anaconda-ks.cfg’Change: 2017-11-12 22:26:50.173018643 -0500[root@lb02 ~]# ls -cmydir  1.sh  anaconda-ks.cfg  #按照ctime排序
-d:仅显示目录名,而不显示目录下的内容列表。显示符号链接文件本身,而不显示其所指向的目录列表;
[root@lb02 ~]# ls -ld .dr-xr-x---. 5 root root 200 Feb 21 06:58 .
-f:此参数的效果和同时指定“aU”参数相同,并关闭“lst”参数的效果;
[root@lb02 ~]# ls -f.   .bash_logout   .bashrc  .tcshrc          .bash_history  .pki  .viminfo..  .bash_profile  .cshrc   anaconda-ks.cfg  .ssh           1.sh  mydir[root@lb02 ~]# ls -aU.   .bash_logout   .bashrc  .tcshrc          .bash_history  .pki  .viminfo..  .bash_profile  .cshrc   anaconda-ks.cfg  .ssh           1.sh  mydir[root@lb02 ~]# ls -lsttotal 8  0 drwxr-xr-x  2 root root    6 Feb 21 06:44 mydir4 -rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh4 -rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfg
-i:显示文件索引节点号(inode)。一个索引节点代表一个文件;
[root@lb02 ~]# ls -i *134435243 1.sh  134318146 anaconda-ks.cfgmydir:
---:与“-F”选项的功能相同,但是不显示“*”;
[root@lb02 ~]# ls --file-type1.sh  anaconda-ks.cfg  mydir/
-k:以KB(千字节)为单位显示文件大小;-l:以长格式显示目录下的内容列表。输出的信息从左到右依次包括文件名,文件类型、权限模式、硬连接数、所有者、组、文件大小和文件的最后修改时间等;
[root@lb02 ~]# ls -ltotal 8-rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh
-m:用“,”号区隔每个文件和目录的名称;
[root@lb02 ~]# ls -m1.sh, anaconda-ks.cfg, mydir
-n:以用户识别码和群组识别码替代其名称;
[root@lb02 ~]# ls -ntotal 8-rwxr-xr-x  1 0 0    9 Feb 21 06:43 1.sh   ##uid 和gid显示-rw-------. 1 0 0 1627 Nov 12 22:26 anaconda-ks.cfg
-r:以文件名反序排列并输出目录内容列表;
[root@lb02 ~]# ls -lttotal 8drwxr-xr-x  2 root root    6 Feb 21 06:44 mydir-rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh-rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfg[root@lb02 ~]# ls -ltr                                  #-t默认按照修改时间Mtime,-r逆序total 8-rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfg    -rwxr-xr-x  1 root root    9 Feb 21 06:43 1.shdrwxr-xr-x  2 root root    6 Feb 21 06:44 mydir
-s:显示文件和目录的大小,以区块为单位;
[root@lb02 ~]# ls -stotal 84 1.sh  4 anaconda-ks.cfg  0 mydir
-t:用文件和目录的更改时间排序;
[root@lb02 ~]# ls -lttotal 8drwxr-xr-x  2 root root    6 Feb 21 06:44 mydir    #默认显示修改时间 -rwxr-xr-x  1 root root    9 Feb 21 06:43 1.sh-rw-------. 1 root root 1627 Nov 12 22:26 anaconda-ks.cfg
-L:如果遇到性质为符号链接的文件或目录,直接列出该链接所指向的原始文件或目录;-R:递归处理,将指定目录下的所有文件及子目录一并处理;
[root@lb02 ~]# ls -R.:1.sh  anaconda-ks.cfg  mydir./mydir:childir  myfile./mydir/childir:my.txt
--full-:列出完整的日期与时间;
[root@lb02 ~]# ls --full-time total 8-rwxr-xr-x  1 root root    9 2018-02-21 06:43:41.248479699 -0500 1.sh-rw-------. 1 root root 1627 2017-11-12 22:26:50.173018643 -0500 anaconda-ks.cfgdrwxr-xr-x  3 root root   35 2018-02-21 07:36:08.614123920 -0500 mydir
--color[=WHEN]:使用不同的颜色高亮显示不同类型的。
[root@lb02 ~]# alias ls   alias ls='ls --color=auto'   #别名默认就有

 

 参考:http://man.linuxde.net/ls

 

转载于:https://www.cnblogs.com/machangwei-8/p/8457372.html

你可能感兴趣的文章
第 138 章 Spark
查看>>
flask 使用 SQLAlchemy 的两种方式
查看>>
Nginx入门笔记之————配置文件结构
查看>>
SQL Server-聚焦深入理解死锁以及避免死锁建议(三十三)
查看>>
Android(Linux)实时监控串口数据
查看>>
Open Sans字体兼容问题解决办法[font-face]
查看>>
现在的我为什么不泡技术论坛了
查看>>
AES加密
查看>>
MPLS LDP随堂笔记1
查看>>
HTTPS 也不安全?被发现新漏洞会暴露你的数据
查看>>
MySQL · 最佳实践 · 什么时候该升级内存规格
查看>>
花卉世界大观园和杂技之游
查看>>
安全问题会对网络购物季产生负面影响吗
查看>>
2016年日本信息安全市场规模分析
查看>>
微软:超过96%的企业用户正在测试Win10
查看>>
Google VC投资SDN初创公司Plexxi
查看>>
英特尔在移动市场另辟蹊径
查看>>
英特尔收购Movidius背后:为什么我们需要一款专门的CV处理芯片?
查看>>
三大新闻机构起诉FBI,FBI与苹果大战续集开幕?
查看>>
未来数据中心的选择:宽带多模光纤
查看>>