Linux中的15个基本‘ls’命令示例

发表于:2015-4-03 09:52

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:tecmint    来源:51Testing软件测试网采编

分享:
  5. 以尾部以‘/’字符结尾的方式列出文件和目录
  使用 ls 命令的 -F 选项,会在每个目录的末尾添加“/”字符显示。
  # ls -F
  0001.pcap        Desktop/    Downloads/        index.html   install.log.syslog  Pictures/  Templates/
  anaconda-ks.cfg  Documents/  fbcmd_update.php  install.log  Music/              Public/    Videos/
  6. 倒序列出文件
  ls -r 选项能以倒序方式显示文件和目录。
  # ls -r
  Videos     Public    Music               install.log  fbcmd_update.php  Documents  anaconda-ks.cfg
  Templates  Pictures  install.log.syslog  index.html   Downloads         Desktop    0001.pcap
  7. 递归列出子目录
  ls -R 选项能列出非常长的目录树,来看看示例输出:
# ls -R
total 1384
-rw-------. 1 root     root      33408 Aug  8 17:25 anaconda.log
-rw-------. 1 root     root      30508 Aug  8 17:25 anaconda.program.log
./httpd:
total 132
-rw-r--r--  1 root root     0 Aug 19 03:14 access_log
-rw-r--r--. 1 root root 61916 Aug 10 17:55 access_log-20120812
./lighttpd:
total 68
-rw-r--r--  1 lighttpd lighttpd  7858 Aug 21 15:26 access.log
-rw-r--r--. 1 lighttpd lighttpd 37531 Aug 17 18:21 access.log-20120819
./nginx:
total 12
-rw-r--r--. 1 root root    0 Aug 12 03:17 access.log
-rw-r--r--. 1 root root  390 Aug 12 03:17 access.log-20120812.gz
  8. 以修改时间倒序列出
  带-ltr组合选项能以文件或目录的最新修改时间的次序来显示它们。
# ls -ltr
total 176
-rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
-rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
-rw-------. 1 root root  1586 Jul 31 02:17 anaconda-ks.cfg
drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Desktop
drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Videos
drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Templates
drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Public
drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Pictures
drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Music
drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Documents
-rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
-rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
drwxr-xr-x. 4 root root  4096 Aug 16 02:55 Downloads
-rw-r--r--. 1 root root   683 Aug 19 09:59 0001.pcap
  9. 按文件大小排序
  带-lS组合选项能按文件从大到小的次序显示。
  # ls -lS
  total 176
  -rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
  -rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
  -rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
  -rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
  drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Desktop
  drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Documents
  drwxr-xr-x. 4 root root  4096 Aug 16 02:55 Downloads
  drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Music
  drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Pictures
  drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Public
  drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Templates
  drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Videos
  -rw-------. 1 root root  1586 Jul 31 02:17 anaconda-ks.cfg
  -rw-r--r--. 1 root root   683 Aug 19 09:59 0001.pcap
  10. 显示文件或目录的索引节点号
  我们有时候可以看到一些数字打印在文件或目录名之前,带-i选项就能列出文件或目录的索引节点号。
  # ls -i
  20112 0001.pcap        23610 Documents         23793 index.html          23611 Music     23597 Templates
  23564 anaconda-ks.cfg  23595 Downloads            22 install.log         23612 Pictures  23613 Videos
  23594 Desktop          23585 fbcmd_update.php     35 install.log.syslog  23601 Public
32/3<123>
重磅发布,2022软件测试行业现状调查报告~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号