概要

英文全称:list
功能:列出目录中的所有文件

  1. [root@kedacom dev]# ls --help
  2. 用法:ls [选项]... [文件]...
  3. List information about the FILEs (the current directory by default).
  4. Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
  5. Mandatory arguments to long options are mandatory for short options too.
  6. -a, --all 不隐藏任何以. 开始的项目
  7. -A, --almost-all 列出除. 及.. 以外的任何项目
  8. --author 与-l 同时使用时列出每个文件的作者
  9. -b, --escape 以八进制溢出序列表示不可打印的字符
  10. --block-size=SIZE scale sizes by SIZE before printing them; e.g.,
  11. '--block-size=M' prints sizes in units of
  12. 1,048,576 bytes; see SIZE format below
  13. -B, --ignore-backups do not list implied entries ending with ~
  14. -c with -lt: sort by, and show, ctime (time of last
  15. modification of file status information);
  16. with -l: show ctime and sort by name;
  17. otherwise: sort by ctime, newest first
  18. -C list entries by columns
  19. --color[=WHEN] colorize the output; WHEN can be 'never', 'auto',
  20. or 'always' (the default); more info below
  21. -d, --directory list directories themselves, not their contents
  22. -D, --dired generate output designed for Emacs' dired mode
  23. -f do not sort, enable -aU, disable -ls --color
  24. -F, --classify append indicator (one of */=>@|) to entries
  25. --file-type likewise, except do not append '*'
  26. --format=WORD across -x, commas -m, horizontal -x, long -l,
  27. single-column -1, verbose -l, vertical -C
  28. --full-time like -l --time-style=full-iso
  29. -g 类似-l,但不列出所有者
  30. --group-directories-first
  31. group directories before files;
  32. can be augmented with a --sort option, but any
  33. use of --sort=none (-U) disables grouping
  34. -G, --no-group 以一个长列表的形式,不输出组名
  35. -h, --human-readable 与-l 一起,以易于阅读的格式输出文件大小
  36. (例如 1K 234M 2G)
  37. --si 同上面类似,但是使用1000 为基底而非1024
  38. -H, --dereference-command-line
  39. follow symbolic links listed on the command line
  40. --dereference-command-line-symlink-to-dir
  41. follow each command line symbolic link
  42. that points to a directory
  43. --hide=PATTERN do not list implied entries matching shell PATTERN
  44. (overridden by -a or -A)
  45. --indicator-style=WORD append indicator with style WORD to entry names:
  46. none (default), slash (-p),
  47. file-type (--file-type), classify (-F)
  48. -i, --inode print the index number of each file
  49. -I, --ignore=PATTERN do not list implied entries matching shell PATTERN
  50. -k, --kibibytes default to 1024-byte blocks for disk usage
  51. -l 使用较长格式列出信息
  52. -L, --dereference 当显示符号链接的文件信息时,显示符号链接所指示
  53. 的对象而并非符号链接本身的信息
  54. -m 所有项目以逗号分隔,并填满整行行宽
  55. -n, --numeric-uid-gid 类似 -l,但列出UID 及GID 号
  56. -N, --literal 输出未经处理的项目名称 (如不特别处理控制字符)
  57. -o 类似 -l,但不列出有关组的信息
  58. -p, --indicator-style=slash 对目录加上表示符号"/"
  59. -q, --hide-control-chars print ? instead of nongraphic characters
  60. --show-control-chars show nongraphic characters as-is (the default,
  61. unless program is 'ls' and output is a terminal)
  62. -Q, --quote-name enclose entry names in double quotes
  63. --quoting-style=WORD use quoting style WORD for entry names:
  64. literal, locale, shell, shell-always, c, escape
  65. -r, --reverse 逆序排列
  66. -R, --recursive 递归显示子目录
  67. -s, --size 以块数形式显示每个文件分配的尺寸
  68. -S sort by file size
  69. --sort=WORD sort by WORD instead of name: none (-U), size (-S),
  70. time (-t), version (-v), extension (-X)
  71. --time=WORD with -l, show time as WORD instead of default
  72. modification time: atime or access or use (-u)
  73. ctime or status (-c); also use specified time
  74. as sort key if --sort=time
  75. --time-style=STYLE with -l, show times using style STYLE:
  76. full-iso, long-iso, iso, locale, or +FORMAT;
  77. FORMAT is interpreted like in 'date'; if FORMAT
  78. is FORMAT1<newline>FORMAT2, then FORMAT1 applies
  79. to non-recent files and FORMAT2 to recent files;
  80. if STYLE is prefixed with 'posix-', STYLE
  81. takes effect only outside the POSIX locale
  82. -t sort by modification time, newest first
  83. -T, --tabsize=COLS assume tab stops at each COLS instead of 8
  84. -u with -lt: sort by, and show, access time;
  85. with -l: show access time and sort by name;
  86. otherwise: sort by access time
  87. -U do not sort; list entries in directory order
  88. -v natural sort of (version) numbers within text
  89. -w, --width=COLS assume screen width instead of current value
  90. -x list entries by lines instead of by columns
  91. -X sort alphabetically by entry extension
  92. -1 list one file per line
  93. SELinux options:
  94. --lcontext Display security context. Enable -l. Lines
  95. will probably be too wide for most displays.
  96. -Z, --context Display security context so it fits on most
  97. displays. Displays only mode, user, group,
  98. security context and file name.
  99. --scontext Display only security context and file name.
  100. --help 显示此帮助信息并退出
  101. --version 显示版本信息并退出
  102. SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units
  103. are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).
  104. 使用色彩来区分文件类型的功能已被禁用,默认设置和 --color=never 同时禁用了它。
  105. 使用 --color=auto 选项,ls 只在标准输出被连至终端时才生成颜色代码。
  106. LS_COLORS 环境变量可改变此设置,可使用 dircolors 命令来设置。
  107. 退出状态:
  108. 0 正常
  109. 1 一般问题 (例如:无法访问子文件夹)
  110. 2 严重问题 (例如:无法使用命令行参数)
  111. GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
  112. 请向<http://translationproject.org/team/zh_CN.html> 报告ls 的翻译错误
  113. 要获取完整文档,请运行:info coreutils 'ls invocation'

带通配符

  1. [root@kedacom dev]# ls fd*
  2. 0 1 2 3
  3. [root@kedacom dev]# ls std*
  4. stderr stdin stdout

列出指定目录

  1. [root@kedacom dev]# ls /home/
  2. es kedacom lisi wang zhang

-l 长格式显示

  1. [root@kedacom dev]# ls -l /home/
  2. 总用量 0
  3. drwx------ 3 es es 76 3 25 2021 es
  4. drwx------ 4 kedacom root 277 1 31 21:58 kedacom
  5. drwxr-xr-x 2 root root 6 2 1 14:19 lisi
  6. drwxr-xr-x 2 root root 6 2 1 14:19 wang
  7. drwxr-xr-x 5 root root 33 2 1 14:19 zhang

-a 全部文件和目录

[root@kedacom ~]# ls -l /home/kedacom/
总用量 650348
-rw-r--r-- 1 kedacom root         6053 1月  31 21:58 all
-rw-r--r-- 1 root    root        19555 12月 31 13:32 choujian1.log
-rw-r--r-- 1 root    root      1204176 12月 31 11:13 choujian_per.log
-rw-r--r-- 1 kedacom root          745 1月  31 21:54 error
-rw-r--r-- 1 root    root     43254688 10月 18 17:31 iau
-rw-r--r-- 1 kedacom root         5308 1月  31 21:54 out
-rw-r--r-- 1 root    root    131447710 12月 23 12:21 slave_exe_install.tar
-rw-r--r-- 1 root    root    431057610 12月 23 12:21 spot_check_system.tar
-rw-r--r-- 1 tcpdump tcpdump  58942461 4月  16 2021 tsu.pcap

#-a显示所有文件,包含隐藏文件,例如:.bash_history   .bash_logout等
[root@kedacom ~]# ls -l -a /home/kedacom/
总用量 650364
drwx------  4 kedacom root          277 1月  31 21:58 .
drwxr-xr-x. 7 root    root           68 2月   1 14:19 ..
-rw-r--r--  1 kedacom root         6053 1月  31 21:58 all
-rw-------  1 kedacom root         1506 1月  31 23:16 .bash_history
-rw-r--r--  1 kedacom root           18 1月   7 2019 .bash_logout
-rw-r--r--  1 kedacom root          193 1月   7 2019 .bash_profile
-rw-r--r--  1 kedacom root          231 1月   7 2019 .bashrc
drwxr-xr-x  3 kedacom root           18 4月  15 2021 .cache
-rw-r--r--  1 root    root        19555 12月 31 13:32 choujian1.log
-rw-r--r--  1 root    root      1204176 12月 31 11:13 choujian_per.log
drwxr-xr-x  3 kedacom root           18 4月  15 2021 .config
-rw-r--r--  1 kedacom root          745 1月  31 21:54 error
-rw-r--r--  1 root    root     43254688 10月 18 17:31 iau
-rw-r--r--  1 kedacom root         5308 1月  31 21:54 out
-rw-r--r--  1 root    root    131447710 12月 23 12:21 slave_exe_install.tar
-rw-r--r--  1 root    root    431057610 12月 23 12:21 spot_check_system.tar
-rw-r--r--  1 tcpdump tcpdump  58942461 4月  16 2021 tsu.pcap

-R 递归显示

[root@kedacom ~]# ls -R /home/
/home/:
es  kedacom  lisi  wang  zhang

/home/es:

/home/kedacom:

/home/lisi:

/home/wang:

/home/zhang:
a  b  c

/home/zhang/a:

/home/zhang/b:

/home/zhang/c:

-d 显示目录本身属性

[root@kedacom ~]# ls -dl /dev
drwxr-xr-x 20 root root 3480 1月  25 16:26 /dev

-r 逆序排序

#未带-r参数
[root@kedacom ~]# ls -l /home/
总用量 0
drwx------ 3 es      es    76 3月  25 2021 es
drwx------ 4 kedacom root 112 2月   1 15:34 kedacom
drwxr-xr-x 2 root    root   6 2月   1 14:19 lisi
drwxr-xr-x 2 root    root   6 2月   1 14:19 wang
drwxr-xr-x 5 root    root  33 2月   1 14:19 zhang

#带-r参数
[root@kedacom ~]# ls -lr /home/
总用量 0
drwxr-xr-x 5 root    root  33 2月   1 14:19 zhang
drwxr-xr-x 2 root    root   6 2月   1 14:19 wang
drwxr-xr-x 2 root    root   6 2月   1 14:19 lisi
drwx------ 4 kedacom root 112 2月   1 15:34 kedacom
drwx------ 3 es      es    76 3月  25 2021 es