ls 中文man页面

系统
程序ls先列出非目录的文件项,然后是每一个目录中的 “可显示”文件。如果没有选项之外的参数【译注:即 文件名部分为空】出现,缺省为 "." (当前目录)。选 项“ -d ”使得目录与非目录项同样对待。除非“ -a ” 选项出现,文件名以“.”开始的文件不属“可显示”文 件。 以当前目录为准,每一组文件(包括非目录文件项,以及 每一内含文件的目录)分别按文件名比较顺序排序。如果 “ -l ”选项存在,每组文件前显示一摘要行——给出该 组文件长度之和(以 512 字节为单位)。 输出是到标准输出( stdout )。除非以“ -C ”选项要 求

NAME

ls, dir, vdir - 列目录内容  

提要

ls [选项] [文件名...]

POSIX 标准选项: [-CFRacdilqrtu1]  

GNU 选项 (短格式):

[-1abcdfgiklmnopqrstuxABCDFGLNQRSUX] [-w cols] [-T cols] [-I pattern] [--full-time] [--format={long,verbose,commas,across,vertical,single-column}] [--sort={none,time,size,extension}] [--time={atime,access,use,ctime,status}] [--color[={none,auto,always}]] [--help] [--version] [--]  

描述( DESCRIPTION )


程序ls先列出非目录的文件项,然后是每一个目录中的 “可显示”文件。如果没有选项之外的参数【译注:即 文件名部分为空】出现,缺省为 "." (当前目录)。选 项“ -d ”使得目录与非目录项同样对待。除非“ -a ” 选项出现,文件名以“.”开始的文件不属“可显示”文 件。 以当前目录为准,每一组文件(包括非目录文件项,以及 每一内含文件的目录)分别按文件名比较顺序排序。如果 “ -l ”选项存在,每组文件前显示一摘要行——给出该 组文件长度之和(以 512 字节为单位)。 输出是到标准输出( stdout )。除非以“ -C ”选项要 求按多列输出,输出将是一行一个。然而,输出到终端时, 单列输出或多列输出是不确定的。可以分别用选项“ -1 ” 或“ -C ”来强制按单列或多列输出。

-C
多列输出,纵向排序。
-F
每个目录名加“ / ”后缀,每个 FIFO 名加“ | ”后缀,每个可运行名加“ * ”后缀。
-R
递归列出遇到的子目录。
-a
列出所有文件,包括以 "." 开头的隐含文件。
-c
使用“状态改变时间”代替“文件修改时间”为依据来排序(使用“ -t ”选项时)或列出(使用“ -l ”选项时)。
-d
将目录名象其它文件一样列出,而不是列出它们的内容。
-i
输出文件前先输出文件系列号(即 i 节点号— i-node number)。 -l 列出(以单列格式)文件模式( file mode ),文件的链接数,所有者名,组名,文件大小(以字节为单位),时间信息,及文件名。缺省时,时间信息显示最近修改时间;可以以选项“ -c ”和“ -u ”选择显示其它两种时间信息。对于设备文件,原先显示文件大小的区域通常显示的是主要和次要的号(majorand minor device numbers)。
-q
将文件名中的非打印字符输出为问号。(对于到终端的输出这是缺省的。)
-r
逆序排列。
-t
按时间信息排序。
-u
使用最近访问时间代替最近修改时间为依据来排序(使用 “ -t ”选项时)或列出(使用“ -l ”选项时)。
-1 单列输出。

GNU 细节

如果标准输出是终端,将多列输出(纵向排序)。

dir ( 也被安装为命令 d ) 等同于“ ls -C ”;即,文件
缺省是多列输出,纵向排序。vdir ( 也被安装为命令 v ) 等同于“ ls -l ”; 即,文件缺省是按长格式输出。

GNU 选项

-1, --format=single-column 一行输出一个文件(单列输出)。如标准输出不是到终端,此选项就是缺省选项。

-a, --all
列出目录中所有文件,包括以“.”开头的文件。
-b, --escape
把文件名中不可输出的字符用反斜杠加字符编号(就象在 C 语言里一样)的形式列出。
-c, --time=ctime, --time=status
按文件状态改变时间(i节点中的ctime)排序并输出目录内容。如采用长格式输出(选项“-l”),使用文件的状态改变时间取代文件修改时间。【译注:所谓文件状态改变(i节点中以ctime标志),既包括文件被修改,又包括文件属性(如所有者、组、链接数等等)的变化】
-d, --directory
将目录名象其它文件一样列出,而不是列出它们的内容。
-f
不排序目录内容;按它们在磁盘上存储的顺序列出。同时启动“ -a ”选项,如果在“ -f ”之前存在“ -l ”、“ - -color ”或“ -s ”,则禁止它们。
-g 忽略,为兼容UNIX用。
-i, --inode
在每个文件左边打印 i 节点号(也叫文件序列号和索引号— — file serial number and index number)。i节点号在每个特定的文件系统中是唯一的。
-k, --kilobytes
如列出文件大小,则以千字节KB为单位。
-l, --format=long, --format=verbose
除每个文件名外,增加显示文件类型、权限、硬链接数、所有者名、组名、大小( byte )、及时间信息(如未指明是其它时间即指修改时间)。对于6个月以上的文件或超出未来 1 小时的文件,时间信息中的时分将被年代取代。 每个目录列出前,有一行“总块数”显示目录下全部文件所占的磁盘空间。块默认是 1024 字节;如果设置了 POSIXLY_CORRECT 的环境变量,除非用“ -k ”选项,则默认块大小是 512 字节。每一个硬链接都计入总块数(因此可能重复计数),这无疑是个缺点。
列出的权限类似于以符号表示(文件)模式的规范。但是 ls
在每套权限的第三个字符中结合了多位( multiple bits )的信息,如下: s 如果设置了 setuid 位或 setgid 位,而且也设置了相应的可执行位。 S 如果设置了 setuid 位或 setgid 位,但是没有设置相应的可执行位。 t 如果设置了 sticky 位,而且也设置了相应的可执行位。 T 如果设置了 sticky 位,但是没有设置相应的可执行位。 x 如果仅仅设置了可执行位而非以上四种情况。 - 其它情况(即可执行位未设置)。
-m, --format=commas
水平列出文件,每行尽可能多,相互用逗号和一个空格分隔。
-n, --numeric-uid-gid
列出数字化的 UID 和 GID 而不是用户名和组名。
-o
以长格式列出目录内容,但是不显示组信息。等于使用“ --format=long --no-group ”选项。提供此选项是为了与其它版本的 ls 兼容。
-p
在每个文件名后附上一个字符以说明该文件的类型。类似“ -F ”选项但是不标示可执行文件。
-q, --hide-control-chars
用问号代替文件名中非打印的字符。这是缺省选项。
-r, --reverse
逆序排列目录内容。
-s, --size
在每个文件名左侧输出该文件的大小,以 1024 字节的块为单位。如果设置了 POSIXLY_CORRECT 的环境变量,除非用“ -k ”选项,块大小是 512 字节。
-t, --sort=time
按文件最近修改时间( i 节点中的 mtime )而不是按文件名字典序排序,新文件靠前。
-u, --time=atime, --time=access, --time=use
类似选项“ -t ”,但是用文件最近访问时间( i 节点中的 atime )取代文件修改时间。如果使用长格式列出,打印的时间是最近访问时间。
-w, --width cols
假定屏幕宽度是 cols ( cols 以实际数字取代)列。如未用此选项,缺省值是这样获得的:如可能先尝试取自终端驱动,否则尝试取自环境变量 COLUMNS (如果设置了的话),都不行则取 80 。
-x, --format=across, --format=horizontal
多列输出,横向排序。
-A, --almost-all
显示除 "." 和 ".." 外的所有文件。
-B, --ignore-backups
不输出以“ ~ ”结尾的备份文件,除非已经在命令行中给出。
-C, --format=vertical
多列输出,纵向排序。当标准输出是终端时这是缺省项。使用命令名 dir 和 d 时,则总是缺省的。
-D, --dired
当采用长格式(“ -l ”选项)输出时,在主要输出后,额外打印一行: //DIRED// BEG1 END1 BEG2 END2 ...
BEGn 和 ENDn 是无符号整数,记录每个文件名的起始、结束位置在输出中的位置(
字节偏移量)。这使得 Emacs 易于找到文件名,即使文件名包含空格或换行等非正常字符也无需特异的搜索。
如果目录是递归列出的(“ -R ”选项),每个子目录后列出类似一行:
//SUBDIRED// BEG1 END1 ... 【译注:我测试了 TurboLinux4.0 和 RedHat6.1 ,发现它们都是在 “ //DIRED// BEG1... ”之后列出“ //SUBDIRED// BEG1 ... ”,也即只有一个而不是在每个子目录后都有。而且“ //SUBDIRED// BEG1 ... ”列出的是各个子目录名的偏移。】
-F, --classify, --file-type
在每个文件名后附上一个字符以说明该文件的类型。“ * ”表示普通的可执行文件; “ / ”表示目录;“ @ ”表示符号链接;“ | ”表示FIFOs;“ = ”表示套接字 (sockets) ;什么也没有则表示普通文件。
-G, --no-group
以长格式列目录时不显示组信息。
-I, --ignorepattern
除非在命令行中给定,不要列出匹配 shell 文件名匹配式( pattern ,不是指一般表达式)的文件。在 shell 中,文件名以 "." 起始的不与在文件名匹配式 (pattern) 开头的通配符匹配。
-L, --dereference
列出符号链接指向的文件的信息,而不是符号链接本身。
-N, --literal
不要用引号引起文件名。
-Q, --quote-name
用双引号引起文件名,非打印字符以 C 语言的方法表示。
-R, --recursive
递归列出全部目录的内容。
-S, --sort=size
按文件大小而不是字典序排序目录内容,大文件靠前。
-T, --tabsize cols
假定每个制表符宽度是 cols 。缺省为 8。为求效率, ls 可能在输出中使用制表符。若 cols 为 0,则不使用制表符。
-U, --sort=none
不排序目录内容;按它们在磁盘上存储的顺序列出。(选项“ -U ”和“ -f ”的不同是前者不启动或禁止相关的选项。)这在列很大的目录时特别有用,因为不加排序能显著的加快速度。
-X, --sort=extension
按文件扩展名(由最后的 "." 之后的字符组成)的字典序排序。没有扩展名的先列出。
--color[=when]
指定是否使用颜色区别文件类别。环境变量 LS_COLORS 指定使用的颜色。如何设置这个变量见 dircolors(1) 。 when 可以被省略,或是以下几项之一:
none 不使用颜色,这是缺省项。
auto 仅当标准输出是终端时使用。 always 总是使用颜色。指定 --color 而且省略 when 时就等同于 --color=always 。
--full-time
列出完整的时间,而不是使用标准的缩写。格式如同 date(1) 的缺省格式;此格式是不能改变的,但是你可以用 cut(1) 取出其中的日期字串并将结果送至命令 “ date -d ”。
输出的时间包括秒是非常有用的。( Unix 文件系统储存文件的时间信息精确到秒,
因此这个选项已经给出了系统所知的全部信息。)例如,当你有一个 Makefile 文件不能恰当的生成文件时,这个选项会提供帮助。

GNU 标准选项

--help
打印用法信息到标准输出并顺利退出。
--version
打印版本信息到标准输出并顺利退出。
--
结束选项表。

环境

变量 POSIXLY_CORRECT 可以决定一组选择。如果没有设置此变量,每个制表符的字符数由变量 TABSIZE 决定。变量 COLUMNS (当它由一个十进制整数表示时)决定输出的列宽度(同“ -C ”选项一起用时)。文件名不得为适应多列输出而被截断。变量 LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES 及 LC_TIME 仍保持原义。变量 TZ 给出时区供 ls 输出相应的时间字串。变量 LS_COLORS 用以决定是否使用颜色。  

已知错误

在 BSD 系统上,对于从 HP-UX 系统上通过 NFS mount 而来的文件,“ -s ”选项报告的大小只有正确值的一半;在 HP-UX 系统上,对于从 BSD 系统上通过 NFS mount 而来的文件, ls 报告的大小则有正确值的两倍。这是 HP-UX 的一个缺陷造成的,它也影响 HP-UX 上的 ls 程序。  

适合到

POSIX 1003.2  

参见

dircolors(1)  

#p#

NAME

ls - list directory contents  

SYNOPSIS

ls [OPTION]... [FILE]...  

DESCRIPTION

List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuSUX nor --sort.

Mandatory arguments to long options are mandatory for short options too.

-a, --all
do not hide entries starting with .
-A, --almost-all
do not list implied . and ..
--author
print the author of each file
-b, --escape
print octal escapes for nongraphic characters
--block-size=SIZE
use SIZE-byte blocks
-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
-C
list entries by columns
--color[=WHEN]
control whether color is used to distinguish file types. WHEN may be `never', `always', or `auto'
-d, --directory
list directory entries instead of contents, and do not dereference symbolic links
-D, --dired
generate output designed for Emacs' dired mode
-f
do not sort, enable -aU, disable -lst
-F, --classify
append indicator (one of */=@|) to entries
--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
-G, --no-group
inhibit display of group information
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
--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
--indicator-style=WORD append indicator with style WORD to entry names:
none (default), classify (-F), file-type (-p)
-i, --inode
print index number of each file
-I, --ignore=PATTERN
do not list implied entries matching shell PATTERN
-k
like --block-size=1K
-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 UIDs and GIDs
-N, --literal
print raw entry names (don't treat e.g. control characters specially)
-o
like -l, but do not list group information
-p, --file-type
append indicator (one of /=@|) to entries
-q, --hide-control-chars
print ? instead of non graphic characters
--show-control-chars
show non graphic characters as-is (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, c, escape
-r, --reverse
reverse order while sorting
-R, --recursive
list subdirectories recursively
-s, --size
print size of each file, in blocks
-S
sort by file size
--sort=WORD
extension -X, none -U, size -S, time -t, version -v
status -c, time -t, atime -u, access -u, use -u
--time=WORD
show time as WORD instead of modification time: atime, access, use, ctime or status; use specified time as sort key if --sort=time
--time-style=STYLE
show times using style STYLE: full-iso, long-iso, iso, locale, +FORMAT
FORMAT is interpreted like `date'; if FORMAT is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed with `posix-', STYLE takes effect only outside the POSIX locale
-t
sort by modification time
-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
-U
do not sort; list entries in directory order
-v
sort by version
-w, --width=COLS
assume screen width instead of current value
-x
list entries by lines instead of by columns
-X
sort alphabetically by entry extension
-1
list one file per line

SELinux options:

--lcontext
Display security context. Enable -l. Lines will probably be too wide for most displays.
-Z, --context
Display security context so it fits on most displays. Displays only mode, user, group, security context and file name.
--scontext
Display only security context and file name.
--help
display this help and exit
--version
output version information and exit

SIZE may be (or may be an integer optionally followed by) one of following: kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

By default, color is not used to distinguish types of files. That is equivalent to using --color=none. Using the --color option without the optional WHEN argument is equivalent to using --color=always. With --color=auto, color codes are output only if standard output is connected to a terminal (tty).  

AUTHOR

Written by Richard Stallman and David MacKenzie.  

REPORTING BUGS

Report bugs to <bug-coreutils@gnu.org>.  

COPYRIGHT

Copyright © 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

SEE ALSO

The full documentation for ls is maintained as a Texinfo manual. If the info and ls programs are properly installed at your site, the command

info coreutils ls

should give you access to the complete manual.

责任编辑:韩亚珊 来源: 互联网
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-25 15:39:42

fcloseall中文man

2011-08-25 15:00:15

cfgetispeed中文man

2011-08-19 18:35:50

issue中文man

2011-08-25 17:03:51

pclose中文man

2011-08-25 17:40:25

setvbuf中文man

2011-08-23 14:21:16

poweroff中文man

2011-08-24 15:52:59

intro中文man

2011-08-23 13:40:31

2011-08-25 15:54:08

ferror中文man

2011-08-25 14:40:27

basename中文man

2011-08-25 17:24:54

puts中文man

2011-08-25 18:34:55

ungetc中文man

2011-08-23 10:03:40

useradd中文man

2011-08-23 10:29:02

chpasswd中文man

2011-08-23 10:34:22

convertquot中文man

2011-08-23 15:39:34

rpmbuild中文man
点赞
收藏

51CTO技术栈公众号