|
10 | 10 | ### 语法 |
11 | 11 |
|
12 | 12 | ```shell |
13 | | -ls(选项)(参数) |
| 13 | +ls [选项] [文件名...] |
14 | 14 | ``` |
15 | 15 |
|
16 | 16 | ### 选项 |
17 | 17 |
|
18 | 18 | ```shell |
19 | | --a, --all # 不隐藏任何以. 开始的项目 |
20 | | --A, --almost-all # 列出除. 及.. 以外的任何项目 |
21 | | - --author # 与-l 同时使用时列出每个文件的作者 |
22 | | --b, --escape # 以八进制溢出序列表示不可打印的字符 |
23 | | - --block-size=SIZE # scale sizes by SIZE before printing them; e.g., |
24 | | - # '--block-size=M' prints sizes in units of |
25 | | - # 1,048,576 bytes; see SIZE format below |
26 | | --B, --ignore-backups # do not list implied entries ending with ~ |
27 | | --c # with -lt: sort by, and show, ctime (time of last |
28 | | - # modification of file status information); |
29 | | - # with -l: show ctime and sort by name; |
30 | | - # otherwise: sort by ctime, newest first |
31 | | --C # list entries by columns |
32 | | - --color[=WHEN] # colorize the output; WHEN can be 'never', 'auto', |
33 | | - # or 'always' (the default); more info below |
34 | | --d, --directory # list directories themselves, not their contents |
35 | | --D, --dired # generate output designed for Emacs' dired mode |
36 | | --f # do not sort, enable -aU, disable -ls --color |
37 | | --F, --classify # append indicator (one of */=>@|) to entries |
38 | | - --file-type # likewise, except do not append '*' |
39 | | - --format=WORD # across -x, commas -m, horizontal -x, long -l, |
40 | | - # single-column -1, verbose -l, vertical -C |
41 | | - --full-time # like -l --time-style=full-iso |
42 | | --g # 类似-l,但不列出所有者 |
43 | | - --group-directories-first |
44 | | - # group directories before files; |
45 | | - # can be augmented with a --sort option, but any |
46 | | - # use of --sort=none (-U) disables grouping |
47 | | --G, --no-group # 以一个长列表的形式,不输出组名 |
48 | | --h, --human-readable # 与-l 一起,以易于阅读的格式输出文件大小 |
49 | | - (例如 1K 234M 2G) |
50 | | - --si # 同上面类似,但是使用1000 为基底而非1024 |
51 | | --H, --dereference-command-line |
52 | | - # follow symbolic links listed on the command line |
53 | | - --dereference-command-line-symlink-to-dir |
54 | | - # follow each command line symbolic link |
55 | | - # that points to a directory |
56 | | - --hide=PATTERN # do not list implied entries matching shell PATTERN |
57 | | - # (overridden by -a or -A) |
58 | | - --indicator-style=WORD # append indicator with style WORD to entry names: |
59 | | - # none (default), slash (-p), |
60 | | - # file-type (--file-type), classify (-F) |
61 | | --i, --inode # print the index number of each file |
62 | | --I, --ignore=PATTERN # do not list implied entries matching shell PATTERN |
63 | | --k, --kibibytes # default to 1024-byte blocks for disk usage |
64 | | --l # 使用较长格式列出信息 |
65 | | --L, --dereference # 当显示符号链接的文件信息时,显示符号链接所指示 |
66 | | - # 的对象而并非符号链接本身的信息 |
67 | | --m # 所有项目以逗号分隔,并填满整行行宽 |
68 | | --n, --numeric-uid-gid # 类似 -l,但列出UID 及GID 号 |
69 | | --N, --literal # 输出未经处理的项目名称 (如不特别处理控制字符) |
70 | | --o # 类似 -l,但不列出有关组的信息 |
71 | | --p, --indicator-style=slash # 对目录加上表示符号"/" |
72 | | --q, --hide-control-chars # print ? instead of nongraphic characters |
73 | | - --show-control-chars # show nongraphic characters as-is (the default, |
74 | | - # unless program is 'ls' and output is a terminal) |
75 | | --Q, --quote-name # enclose entry names in double quotes |
76 | | - --quoting-style=WORD # use quoting style WORD for entry names: |
77 | | - # literal, locale, shell, shell-always, c, escape |
78 | | --r, --reverse # 逆序排列 |
79 | | --R, --recursive # 递归显示子目录 |
80 | | --s, --size # 以块数形式显示每个文件分配的尺寸 |
81 | | --S # sort by file size |
82 | | - --sort=WORD # sort by WORD instead of name: none (-U), size (-S), |
83 | | - # time (-t), version (-v), extension (-X) |
84 | | - --time=WORD # with -l, show time as WORD instead of default |
85 | | - # modification time: atime or access or use (-u) |
86 | | - # ctime or status (-c); also use specified time |
87 | | - # as sort key if --sort=time |
88 | | - --time-style=STYLE # with -l, show times using style STYLE: |
89 | | - # full-iso, long-iso, iso, locale, or +FORMAT; |
90 | | - # FORMAT is interpreted like in 'date'; if FORMAT |
91 | | - # is FORMAT1<newline>FORMAT2, then FORMAT1 applies |
92 | | - # to non-recent files and FORMAT2 to recent files; |
93 | | - # if STYLE is prefixed with 'posix-', STYLE |
94 | | - # takes effect only outside the POSIX locale |
95 | | --t # sort by modification time, newest first |
96 | | --T, --tabsize=COLS # assume tab stops at each COLS instead of 8 |
97 | | --u # with -lt: sort by, and show, access time; |
98 | | - # with -l: show access time and sort by name; |
99 | | - # otherwise: sort by access time |
100 | | --U # do not sort; list entries in directory order |
101 | | --v # natural sort of (version) numbers within text |
102 | | --w, --width=COLS # assume screen width instead of current value |
103 | | --x # list entries by lines instead of by columns |
104 | | --X # sort alphabetically by entry extension |
105 | | --1 # list one file per line |
106 | | - |
107 | | -SELinux options: |
108 | | - |
109 | | ---lcontext # Display security context. Enable -l. Lines |
110 | | - # will probably be too wide for most displays. |
111 | | --Z, --context # Display security context so it fits on most |
112 | | - # displays. Displays only mode, user, group, |
113 | | - # security context and file name. |
114 | | ---scontext # Display only security context and file name. |
115 | | - --help # 显示此帮助信息并退出 |
116 | | - --version # 显示版本信息并退出 |
| 19 | +-C # 多列输出,纵向排序。 |
| 20 | +-F # 每个目录名加 "/" 后缀,每个 FIFO 名加 "|" 后缀, 每个可运行名加“ * ”后缀。 |
| 21 | +-R # 递归列出遇到的子目录。 |
| 22 | +-a # 列出所有文件,包括以 "." 开头的隐含文件。 |
| 23 | +-c # 使用“状态改变时间”代替“文件修改时间”为依据来排序(使用“-t”选项时)或列出(使用“-l”选项时)。 |
| 24 | +-d # 将目录名象其它文件一样列出,而不是列出它们的内容。 |
| 25 | +-i # 输出文件前先输出文件系列号(即 i 节点号: i-node number)。 -l 列出(以单列格式)文件模式(file mode),文件的链 接数,所有者名,组名,文件大小(以字节为单位),时间信息,及文件名。缺省时,时间信息显示最近修改时间;可以以选项“-c”和“-u”选择显示其它两种时间信息。对于设 备文件,原先显示文件大小的区域通常显示的是主要和次要的号(majorand minor device numbers)。 |
| 26 | +-q # 将文件名中的非打印字符输出为问号。(对于到终端的输出这是缺省的。) |
| 27 | +-r # 逆序排列。 |
| 28 | +-t # 按时间信息排序。 |
| 29 | +-u # 使用最近访问时间代替最近修改时间为依据来排序(使用“-t”选项时)或列出(使用“-l”选项时)。 |
| 30 | +-1 # 单列输出。 |
| 31 | +-1, --format=single-column # 一行输出一个文件(单列输出)。如标准输出不是到终端,此选项就是缺省选项。 |
| 32 | +-a, --all # 列出目录中所有文件,包括以“.”开头的文件。 |
| 33 | +-b, --escape # 把文件名中不可输出的字符用反斜杠加字符编号(就象在 C 语言里一样)的形式列出。 |
| 34 | +-c, --time=ctime, --time=status |
| 35 | + # 按文件状态改变时间(i节点中的ctime)排序并输出目录内 |
| 36 | + # 容。如采用长格式输出(选项“-l”),使用文件的状态改 |
| 37 | + # 变时间取代文件修改时间。【译注:所谓文件状态改变(i节 |
| 38 | + # 点中以ctime标志),既包括文件被修改,又包括文件属性( 如所有者、组、链接数等等)的变化】 |
| 39 | +-d, --directory |
| 40 | + # 将目录名象其它文件一样列出,而不是列出它们的内容。 |
| 41 | +-f # 不排序目录内容;按它们在磁盘上存储的顺序列出。同时启 动“ -a ”选项,如果在“ -f ”之前存在“ -l |
| 42 | + # ”、“ - -color ”或“ -s ”,则禁止它们。 |
| 43 | +-g # 忽略,为兼容UNIX用。 |
| 44 | +-i, --inode |
| 45 | + # 在每个文件左边打印 i 节点号(也叫文件序列号和索引号: file serial number and index num‐ |
| 46 | + # ber)。i节点号在每个特定的文件系统中是唯一的。 |
| 47 | +-k, --kilobytes |
| 48 | + # 如列出文件大小,则以千字节KB为单位。 |
| 49 | +-l, --format=long, --format=verbose |
| 50 | + # 除每个文件名外,增加显示文件类型、权限、硬链接数、所 有者名、组名、大小( byte |
| 51 | + # )、及时间信息(如未指明是 其它时间即指修改时间)。对于6个月以上的文件或超出未来 1 |
| 52 | + # 小时的文件,时间信息中的时分将被年代取代。 |
| 53 | + # 每个目录列出前,有一行“总块数”显示目录下全部文件所 占的磁盘空间。块默认是 1024 |
| 54 | + # 字节;如果设置了 POSIXLY_CORRECT 的环境变量,除非用“ -k ”选项,则默认块大小是 512 字 |
| 55 | + # 节。每一个硬链接都计入总块数(因此可能重复计数),这无 疑是个缺点。 |
| 56 | + |
| 57 | +# 列出的权限类似于以符号表示(文件)模式的规范。但是 ls |
| 58 | + # 在每套权限的第三个字符中结合了多位( multiple bits ) 的信息,如下: s 如果设置了 setuid |
| 59 | + # 位或 setgid 位,而且也设置了相应的可执行位。 S 如果设置了 setuid 位或 setgid |
| 60 | + # 位,但是没有设置相应的可执行位。 t 如果设置了 sticky 位,而且也设置了相应的可执行位。 T |
| 61 | + # 如果设置了 sticky 位,但是没有设置相应的可执行位。 x |
| 62 | + # 如果仅仅设置了可执行位而非以上四种情况。 - 其它情况(即可执行位未设置)。 |
| 63 | +-m, --format=commas |
| 64 | + # 水平列出文件,每行尽可能多,相互用逗号和一个空格分隔。 |
| 65 | +-n, --numeric-uid-gid |
| 66 | + # 列出数字化的 UID 和 GID 而不是用户名和组名。 |
| 67 | +-o # 以长格式列出目录内容,但是不显示组信息。等于使用“ --format=long --no-group |
| 68 | + # ”选项。提供此选项是为了与其它版本的 ls 兼容。 |
| 69 | +-p # 在每个文件名后附上一个字符以说明该文件的类型。类似“ -F ”选项但是不 标示可执行文件。 |
| 70 | +-q, --hide-control-chars |
| 71 | + # 用问号代替文件名中非打印的字符。这是缺省选项。 |
| 72 | +-r, --reverse |
| 73 | + # 逆序排列目录内容。 |
| 74 | +-s, --size |
| 75 | + # 在每个文件名左侧输出该文件的大小,以 1024 字节的块为单位。如果设置了 POSIXLY_CORRECT |
| 76 | + # 的环境变量,除非用“ -k ”选项,块大小是 512 字节。 |
| 77 | +-t, --sort=time |
| 78 | + # 按文件最近修改时间( i 节点中的 mtime )而不是按文件名字典序排序,新文件 靠前。 |
| 79 | +-u, --time=atime, --time=access, --time=use |
| 80 | + # 类似选项“ -t ”,但是用文件最近访问时间( i 节点中的 atime )取代文件修 |
| 81 | + # 改时间。如果使用长格式列出,打印的时间是最近访问时间。 |
| 82 | +-w, --width cols |
| 83 | + # 假定屏幕宽度是 cols ( cols 以实际数字取代)列。如未用此选项,缺省值是这 |
| 84 | + # 样获得的:如可能先尝试取自终端驱动,否则尝试取自环境变量 COLUMNS (如果设 |
| 85 | + # 置了的话),都不行则取 80 。 |
| 86 | + |
| 87 | +-x, --format=across, --format=horizontal |
| 88 | + # 多列输出,横向排序。 |
| 89 | + |
| 90 | +-A, --almost-all |
| 91 | + # 显示除 "." 和 ".." 外的所有文件。 |
| 92 | + |
| 93 | +-B, --ignore-backups |
| 94 | + # 不输出以“ ~ ”结尾的备份文件,除非已经在命令行中给出。 |
| 95 | + |
| 96 | +-C, --format=vertical |
| 97 | + # 多列输出,纵向排序。当标准输出是终端时这是缺省项。使用命令名 dir 和 d 时, 则总是缺省的。 |
| 98 | + |
| 99 | +-D, --dired |
| 100 | + # 当采用长格式(“-l”选项)输出时,在主要输出后,额外打印一行: //DIRED// BEG1 END1 BEG2 |
| 101 | + # END2 ... |
| 102 | + |
| 103 | +# BEGn 和 ENDn 是无符号整数,记录每个文件名的起始、结束位置在输出中的位置( |
| 104 | +# 字节偏移量)。这使得 Emacs 易于找到文件名,即使文件名包含空格或换行等非正 |
| 105 | +# 常字符也无需特异的搜索。 |
| 106 | +# |
| 107 | +# 如果目录是递归列出的(“ -R ”选项),每个子目录后列出类似一行: |
| 108 | + # //SUBDIRED// BEG1 END1 ... 【译注:我测试了 TurboLinux4.0 和 RedHat6.1 ,发现它们都是在 “ |
| 109 | + # //DIRED// BEG1... ”之后列出“ //SUBDIRED// BEG1 ... ”,也即只有一个 |
| 110 | + # 而不是在每个子目录后都有。而且“ //SUBDIRED// BEG1 ... ”列出的是各个子目 录名的偏移。】 |
| 111 | + |
| 112 | +-F, --classify, --file-type |
| 113 | + # 在每个文件名后附上一个字符以说明该文件的类型。“ * ”表示普通的可执行文件; “ / ”表示目录;“ |
| 114 | + # @ ”表示符号链接;“ | ”表示FIFOs;“ = ”表示套接字 (sockets) ;什么也没有则表示普通文件。 |
| 115 | + |
| 116 | +-G, --no-group |
| 117 | + # 以长格式列目录时不显示组信息。 |
| 118 | + |
| 119 | +-I, --ignorepattern |
| 120 | + # 除非在命令行中给定,不要列出匹配shell文件名匹配式(pattern ,不是指一般 |
| 121 | + # 表达式)的文件。在shell中,文件名以"."起始的不与在文件名匹配式(pattern) |
| 122 | + # 开头的通配符匹配。 |
| 123 | + |
| 124 | +-L, --dereference |
| 125 | + # 列出符号链接指向的文件的信息,而不是符号链接本身。 |
| 126 | + |
| 127 | +-N, --literal |
| 128 | + # 不要用引号引起文件名。 |
| 129 | + |
| 130 | +-Q, --quote-name |
| 131 | + # 用双引号引起文件名,非打印字符以 C 语言的方法表示。 |
| 132 | + |
| 133 | +-R, --recursive |
| 134 | + # 递归列出全部目录的内容。 |
| 135 | + |
| 136 | +-S, --sort=size |
| 137 | + # 按文件大小而不是字典序排序目录内容,大文件靠前。 |
| 138 | + |
| 139 | +-T, --tabsize cols |
| 140 | + # 假定每个制表符宽度是 cols 。缺省为 8。为求效率, ls 可能在输出中使用制表符。 若 cols 为 |
| 141 | + 0,则不使用制表符。 |
| 142 | + |
| 143 | +-U, --sort=none |
| 144 | + # 不排序目录内容;按它们在磁盘上存储的顺序列出。(选项“-U”和“-f”的不 |
| 145 | + # 同是前者不启动或禁止相关的选项。)这在列很大的目录时特别有用,因为不加排序 |
| 146 | + # 能显著的加快速度。 |
| 147 | + |
| 148 | +-X, --sort=extension |
| 149 | + # 按文件扩展名(由最后的 "." 之后的字符组成)的字典序排序。没有扩展名的先列 出。 |
| 150 | + |
| 151 | +--color[=when] |
| 152 | + # 指定是否使用颜色区别文件类别。环境变量 LS_COLORS 指定使用的颜色。如何设置 这个变量见 dir‐ |
| 153 | + # colors(1) 。 when 可以被省略,或是以下几项之一: |
| 154 | +none # 不使用颜色,这是缺省项。 |
| 155 | + # auto 仅当标准输出是终端时使用。 always 总是使用颜色。指定 --color 而且省略 when 时就等同于 |
| 156 | + # --color=always 。 |
| 157 | + |
| 158 | +--full-time |
| 159 | + # 列出完整的时间,而不是使用标准的缩写。格式如同 date(1) 的缺省格式;此格式 |
| 160 | + # 是不能改变的,但是你可以用 cut(1) 取出其中的日期字串并将结果送至命令 “ date -d ”。 |
| 161 | + |
| 162 | +# 输出的时间包括秒是非常有用的。( Unix 文件系统储存文件的时间信息精确到秒, |
| 163 | + # 因此这个选项已经给出了系统所知的全部信息。)例如,当你有一个 Makefile 文件 |
| 164 | + # 不能恰当的生成文件时,这个选项会提供帮助。 |
117 | 165 | ``` |
118 | 166 |
|
119 | 167 | ### 参数 |
|
0 commit comments