2019-08-05
linux
00
请注意,本文编写于 2096 天前,最后修改于 551 天前,其中某些信息可能已经过时。

目录

ls
使用
语法
参数
实例

ls

ls(英文 : list directory contents)命令用于显示指定工作目录下之内容,列出目前工作目录所含的文件及子目录

使用

所有使用者

语法

ls [-albrtAFR] [name...]

参数

常用参数 ls -l 可以缩写为 ll
-a 或 --all 显示所有文件和目录(文件夹)包括隐藏文件(以.开头文件)
-A 或 --almost-all 和小a相同,但是不显示当前目录及父目录(.和..) -b 或 --escape 打印非图形字符的 C 风格转义符
--block-size=SIZE 和 -l,打印时按 SIZE 缩放大小
例如,'--block-size=M';
-B 或 --ignore-backups 不列出以 ~ 结尾的隐含条目
-c 或 --escape 打印非图形字符的 C 风格转义符
-d 或 --directory 只显示目录 -D 或 --dired 生成为 Emacs 的 dired 模式设计的输出(和普通ls没区别) -f 显示全部文件不显示文件属性颜色,等于-aU,禁用-ls --color -F 或 --classify 将指示符(/=>@| 之一)附加到条目
--file-type 和--classify类似,只是不显示 '
'
--format=WORD 横跨 -x,逗号 -m,水平显示-x, 竖列 -l,单列 -1, verbose -l, vertical -C
--full-time 类似-l ,长显示文件时间信息 -g 类似-l, 但不显示所有者
--group-directories-first 在文件之前对目录进行分组; 可以使用 --sort 选项进行扩充,但任何使用 --sort=none (-U) 禁用分组
-G 或 --no-group 在长列表中,不打印组名
-h 或 --human-readable with -l and -s, print sizes like 1K 234M 2G etc.
--si 同样,但使用 1000 的幂而不是 1024
-H 或 --dereference-命令行按照命令行上列出的符号链接
-i 或 --inode 打印每个文件的索引号
-I 或 --ignore=PATTERN 不列出匹配 shell PATTERN 的隐含条目
-k 或 --kibibytes 默认为 1024 字节块用于磁盘使用; 仅与 -s 和每个目录总数一起使用
-l 使用长列表格式
-L 或 --dereference 当显示符号的文件信息时链接,显示文件的信息链接参考而不是链接本身
-m 用逗号分隔的条目列表填充宽度
-n 或 --numeric-uid-gid 类似于 -l,但列出数字用户和组 ID
-N 或 --literal 不带引号的打印条目名称
-o 类似于-l,但不列出组信息 -p 或 --indicator-style=斜杠 ,将 / 指示器附加到目录 -q 或 --hide-control-chars 打印 ? 而不是非图形字符
--show-control-chars 按原样显示非图形字符(默认除非程序是'ls'并且输出是一个终端) -Q 或 --quote-name 用双引号将条目名称括起来
--quoting-style=WORD 对条目名称使用引用样式 WORD: 文字,语言环境,shell,shell-always, shell-escape,shell-escape-always,c,escape (覆盖 QUOTING_STYLE 环境变量)
-r 或 --reverse 排序时倒序
-R 或 --recursive 递归列出子目录 -s 或 --size 打印每个文件的分配大小,以块为单位
-S 按文件大小排序,最大的在前
--sort=WORD 按 WORD 而不是名称排序:无 (-U)、大小 (-S)、时间 (-t)、版本 (-v)、扩展 (-X)
--time=WORD 和 -l,将时间显示为 WORD 而不是默认值,修改时间:atime or access or use (-u); ctime 或状态 (-c); 也用指定的时间作为排序键,如果 --sort=time(最新的优先)
--time-style=TIME_STYLE 时间/日期格式加上-l; 请参阅下面的TIME_STYLE
-t 按修改时间排序,最新的在前 -T 或 --tabsize=COLS 假定制表符停止在每个 COLS 而不是 8 -u 和 -lt:按访问时间排序并显示; with -l:显示访问时间并按名称排序;否则:按访问时间排序,最新的在前
-U 不排序; 按目录顺序列出条目
-v 文本中自然排序的(版本)数字
-w 或 --width=COLS 将输出宽度设置为 COLS。 0表示没有限制
-x 按行而不是按列列出条目
-X 按条目扩展名的字母顺序排序
-Z 或 --context 打印每个文件的任何安全上下文
-1 每行列出一个文件。 避免使用 -q 或 -b 的 '\n'
--help 显示帮助并退出
--version 输出版本信息并退出

原文

-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file -b, --escape print C-style escapes for nongraphic characters
--block-size=SIZE with -l, scale sizes by SIZE when printing them;
e.g., '--block-size=M'; see SIZE format below
-B, --ignore-backups do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; otherwise: sort by ctime, newest first -C list entries by columns --color[=WHEN] colorize the output; WHEN can be 'always' (default if omitted), 'auto', or 'never'; more info below
-d, --directory list directories themselves, not their contents
-D, --dired generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -ls --color
-F, --classify append indicator (one of /=>@|) to entries
--file-type likewise, except do not append '
'
--format=WORD across -x, commas -m, horizontal -x, long -l, single-column -1, verbose -l, vertical -C
--full-time like -l --time-style=full-iso
-g like -l, but do not list owner --group-directories-first group directories before files; can be augmented with a --sort option, but any use of --sort=none (-U) disables grouping -G, --no-group in a long listing, don't print group names
-h, --human-readable with -l and -s, print sizes like 1K 234M 2G etc.
--si likewise, but use powers of 1000 not 1024
-H, --dereference-command-line follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir follow each command line symbolic link that points to a directory
--hide=PATTERN do not list implied entries matching shell PATTERN (overridden by -a or -A)
--hyperlink[=WHEN] hyperlink file names; WHEN can be 'always' (default if omitted), 'auto', or 'never'
--indicator-style=WORD append indicator with style WORD to entry names: none (default), slash (-p), file-type (--file-type), classify (-F) -i, --inode print the index number of each file
-I, --ignore=PATTERN do not list implied entries matching shell PATTERN
-k, --kibibytes default to 1024-byte blocks for disk usage; used only with -s and per directory totals
-l use a long listing format
-L, --dereference when showing file information for a symbolic link, show information for the file the link
references rather than for the link itself
-m fill width with a comma separated list of entries
-n, --numeric-uid-gid like -l, but list numeric user and group IDs
-N, --literal print entry names without quoting
-o like -l, but do not list group information
-p, --indicator-style=slash
append / indicator to directories
-q, --hide-control-chars print ? instead of nongraphic characters
--show-control-chars show nongraphic characters as-is (the default, unless program is 'ls' and output is a terminal)
-Q, --quote-name enclose entry names in double quotes
--quoting-style=WORD use quoting style WORD for entry names: literal, locale, shell, shell-always, shell-escape, shell-escape-always, c, escape (overrides QUOTING_STYLE environment variable)
-r, --reverse reverse order while sorting
-R, --recursive list subdirectories recursively
-s, --size print the allocated size of each file, in blocks
-S sort by file size, largest first --sort=WORD sort by WORD instead of name: none (-U), size (-S), time (-t), version (-v), extension (-X) --time=WORD with -l, show time as WORD instead of default modification time: atime or access or use (-u); ctime or status (-c); also use specified time as sort key if --sort=time (newest first) --time-style=TIME_STYLE time/date format with -l; see TIME_STYLE below
-t sort by modification time, newest first
-T, --tabsize=COLS assume tab stops at each COLS instead of 8
-u with -lt: sort by, and show, access time; with -l: show access time and sort by name; otherwise: sort by access time, newest first
-U do not sort; list entries in directory order
-v natural sort of (version) numbers within text
-w, --width=COLS set output width to COLS. 0 means no limit
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-Z, --context print any security context of each file
-1 list one file per line. Avoid '\n' with -q or -b --help display this help and exit
--version output version information and exit

实例

查看 /(根) 下目录及文件

shell
ls /

查看 /(根) 下全部目录及文件

shell
ls -l /

可以缩写为(ll)

shell
ll /

注:
TIME_STYLE 参数可以是 full-iso、long-iso、iso、locale 或 +FORMAT。 FORMAT 的解释类似于 date(1)。 如果 FORMAT 是 FORMAT1FORMAT2, 然后 FORMAT1 适用于非最近的文件和 FORMAT2 适用于最近的文件。 以"posix-"为前缀的 TIME_STYLE 仅在 POSIX 语言环境之外生效。 TIME_STYLE 环境变量也设置要使用的默认样式。
1.ls (GNU coreutils) 8.30
2.SIZE 参数是一个整数和可选单位(例如:10K 是 10*1024)。
单位是 K、M、G、T、P、E、Z、Y(1024 的幂)或 KB、MB、...(1000 的幂)。
3.使用颜色区分文件类型在默认情况下是禁用的,
使用 --color=never。 使用 --color=auto,
ls 仅在以下情况下发出颜色代码 标准输出连接到终端。 LS_COLORS 环境 变量可以更改设置。 使用 dircolors 命令设置它。
4.退出状态:
0 如果正常
1 如果出现小问题(例如,无法访问子目录)
2 如果出现严重问题(例如,无法访问命令行参数)