ls
tips:
虽然在终端是每行有多个名称,但是输出的时候是按行输出

语法

ls [OPTION]… [FILE]…

参数

参数描述
-a, –all不乎略素有的隐藏文件
-A, –almost-alldo not list implied . and ..
–author使用-l列出文件的作者
-b, –escapeprint C-style escapes for nongraphic characters
–block-size=SIZEscale sizes by SIZE before printing them; e.g., ‘–block-size=M’ prints sizes in units of 1,048,576 bytes; see SIZE format below
-B, –ignore-backups不列出名称以~结尾的文件
-cwith -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
-Clist entries by columns
–color[=WHEN]colorize the output; WHEN can be ‘always’ (default if omitted),’auto’, or ‘never’; more info below
-d, –directorylist directories themselves, not their contents
-D, –diredgenerate output designed for Emacs’ dired mode
-fdo not sort, enable -aU, disable -ls –color
-F, –classifyappend indicator (one of */=>@
–file-typelikewise, except do not append ‘*’
–format=WORDacross -x, commas -m, horizontal -x, long -l, single-column -1,verbose -l, vertical -C
–full-timelike -l –time-style=full-iso
-glike -l, but do not list owner
–group-directories-firstgroup directories before files;can be augmented with a –sort option, but any use of –sort=none (-U) disables grouping
-G, –no-groupin a long listing, don’t print group names
-h, –human-readablewith -l and/or -s, print human readable sizes (e.g., 1K 234M 2G)
–silikewise, but use powers of 1000 not 1024
-H, –dereference-command-linefollow symbolic links listed on the command line
–dereference-command-line-symlink-to-dirfollow each command line symbolic link that points to a directory
–hide=PATTERNdo not list implied entries matching shell PATTERN (overridden by -a or -A)
–indicator-style=WORDappend indicator with style WORD to entry names: none (default), slash (-p), file-type (–file-type), classify (-F)
-i, –inode打印索引
-I, –ignore=PATTERNdo not list implied entries matching shell PATTERN
-k, –kibibytesdefault to 1024-byte blocks for disk usage
-l使用长列表格式
-mfill width with a comma separated list of entries
-n, –numeric-uid-gidlike -l, but list numeric user and group IDs
-N, –literalprint raw entry names (don’t treat e.g. control characters spe‐cially)
-o类似于-l,但是不罗列组信息
-p, –indicator-style=slashappend / indicator to directories
-q, –hide-control-charsprint ? instead of nongraphic characters
–show-control-charsshow nongraphic characters as-is (the default, unless program is ‘ls’ and output is a terminal)
-Q, –quote-nameenclose entry names in double quotes
–quoting-style=WORDuse quoting style WORD for entry names: literal, locale, shell,shell-always, shell-escape, shell-escape-always, c, escape
-r, –reversereverse order while sorting
-R, –recursivelist subdirectories recursively
-Ssort by file size, largest first
–sort=WORDsort by WORD instead of name: none (-U), size (-S), time (-t),version (-v), extension (-X)
–time=WORDwith -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=STYLEwith -l, show times using style STYLE: full-iso, long-iso, iso,locale, or +FORMAT; FORMAT is interpreted like in ‘date’; if FORMAT is FORMAT1FORMAT2, then FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is pre‐ fixed with ‘posix-‘, STYLE takes effect only outside the POSIX locale
-tsort by modification time, newest first
-T, –tabsize=COLSassume tab stops at each COLS instead of 8
-uwith -lt: sort by, and show, access time; with -l: show access time and sort by name; otherwise: sort by access time, newest first
-Udo not sort; list entries in directory order
-vnatural sort of (version) numbers within text
-w, –width=COLSset output width to COLS. 0 means no limit
-xlist entries by lines instead of by columns
-Xsort alphabetically by entry extension
-Z, –contextprint any security context of each file
-1list one file per line. Avoid ‘\n’ with -q or -b

测试:
在文件夹中新建两个文件”a.txt”,”b.txt”和一个文件夹”.a”

claroja@ubuntu:~/test$ tree -a ~/test
/home/claroja/test
├── .a
├── a.txt
└── b.txt
1 directory, 2 files

ls

claroja@ubuntu:~/test$ ls
a.txt  b.txt

ls -a

claroja@ubuntu:~/test$ ls -a
.  ..  .a  a.txt  b.txt

ls -A

claroja@ubuntu:~/test$ ls -A
.a  a.txt  b.txt

ls -author

claroja@ubuntu:~/test$ ls -author
total 12K
-rw-rw-r--  1 claroja    0 629 17:37 a.txt
-rw-rw-r--  1 claroja    0 629 17:38 b.txt
drwxrwxr-x  3 claroja 4.0K 629 17:39 .
drwxrwxr-x  2 claroja 4.0K 629 17:40 .a
drwxr-xr-x 38 claroja 4.0K 629 17:40 ..

ls -b

不知道什么意思

ls -B

不输出以~结尾的文件

ls -ltc -lc -c

claroja@ubuntu:~/test$ ls -ltc #按时间排序显示详细信息,倒序
total 0
-rw-rw-r-- 1 claroja claroja 0 629 17:38 b.txt
-rw-rw-r-- 1 claroja claroja 0 629 17:37 a.txt
claroja@ubuntu:~/test$ ls -lc #按名称排序显示详细信息,升序
total 0
-rw-rw-r-- 1 claroja claroja 0 629 17:37 a.txt
-rw-rw-r-- 1 claroja claroja 0 629 17:38 b.txt
claroja@ubuntu:~/test$ ls -c #按时间排序,倒序
b.txt  a.txt

ls -C

未知

ls -d

claroja@ubuntu:~/test$ ls -d #列出目录
.

ls -D

未知

ls -f

未知

ls -F

未知

ls -f

不排序,这样会减少命令的时间

ls -g

claroja@ubuntu:~/test$ ls -g # 不列出所有者
total 0
-rw-rw-r-- 1 claroja 0 629 17:37 a.txt
-rw-rw-r-- 1 claroja 0 629 17:38 b.txt

ls -G

未知

ls -lh

使得大小显示符合人的阅读习惯

ls -H

未知

ls -i

claroja@ubuntu:~/test$ ls -i #列出文章id
5382202 a.txt  5382204 b.txt

ls -I

未知

ls -k

未知

ls -l

claroja@ubuntu:~/test$ ls -l
total 0
-rw-rw-r-- 1 claroja claroja 0 629 17:37 a.txt
-rw-rw-r-- 1 claroja claroja 0 629 17:38 b.txt

ls -L

未知

Logo

更多推荐