Ax 帮助文档
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 -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
所有文件,包括隐藏文件
-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
反转
-r, --reverse
reverse order while sorting
递归
-R, --recursive
list subdirectories recursively
打印非图形字符的c风格转义
-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, --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
显示list不显示组信息
-o like -l, but do not list group information
显示list
-l use a long listing format
显示list,只显示组和用户的ID
-n, --numeric-uid-gid
like -l, but list numeric user and group IDs
显示链接指定的文件,而不是链接
-L, --dereference
when showing file information for a symbolic link, show information for the file the link references rather than for the link itself
-N, --literal
print entry names without quoting
添加指示器到目录
-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
用逗号分隔
-m fill width with a comma separated list of entries
--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)
打印每个文件分配的大小,在块中
-s, --size
print the allocated size of each file, in blocks
大小可读
-h, --human-readable
with -l and -s, print sizes like 1K 234M 2G etc.
大小以1000单位
--si likewise, but use powers of 1000 not 1024
--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
按大小排列,从大到小
-S sort by file size, largest first
按时间排列,从新到旧
-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
The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).
The TIME_STYLE argument can be full-iso, long-iso, iso, locale, or +FORMAT. FORMAT is interpreted like in date(1). If FORMAT is FORMAT1FORMAT2, then FORMAT1 applies to non-recent
files and FORMAT2 to recent files. TIME_STYLE prefixed with 'posix-' takes effect only outside the POSIX locale. Also the TIME_STYLE environment variable sets the default style to use.
Using color to distinguish file types is disabled both by default and with --color=never. With --color=auto, ls emits color codes only when standard output is connected to a terminal. The
LS_COLORS environment variable can change the settings. Use the dircolors command to set it.
Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory),
2 if serious trouble (e.g., cannot access command-line argument).
AUTHOR
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS
GNU coreutils online help:
Report ls translation bugs to
COPYRIGHT
Copyright © 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
Full documentation at:
or available locally via: info '(coreutils) ls invocation'
Bx 高级用法
1.遍历目录,并显示详细信息。
$ ls -lR
2.列出目录下的abc开头的文件
$ ls -l abc*
3.只列出目录下的子目录并显示文件格式
$ ls <-F> or <-p> test | grep /$
ls -l test | grep “^d” # 因为-l输出的都是d开头的,d是文件夹,这样就可以过滤文件夹了
ls -d */ # -d 像目录一样显示,所以不显示其下的文件
4.按时间顺序,越新越后面
$ ls -ltr # 如果想越新的越前面,把r去掉,方向输出的意思
5.按文件大小排序
$ ls -lhS # -h 将大小从直接变为可读单位,S文件大小排序,文件越大越前,加-r相反
6.统计文件数和目录数
$ ls -l | grep "^-" | wc -l # 以-开头,就是普通文件,再wc -l统计过滤后的普通文件个数。
$ ls -l | grep "^d" | wc -l # 以目录开头,统计个数
7.列出文件的绝对路径
$ ls | sed "s:^:`pwd`/:" # sed 表示在行首添加路径pwd
8.列出文件的绝对路径且显示隐藏文件,并不对目录递归
$ find $PWD -maxdepth 1 | xargs ls -ld