ls - list directory contents
man ls 查看使用幫助
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
-b, --escape
print octal escapes for nongraphic characters
--block-size=SIZE
use SIZE-byte blocks. 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
-C list entries by columns
--color[=WHEN]
colorize the output. WHEN defaults to ‘always’ or can be ‘never’ or ‘auto’. More info below
-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 -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.
augment 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, 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
--hide=PATTERN
do not list implied entries matching shell PATTERN (overridden by -a or -A)
--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 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 user and group IDs
-N, --literal
print raw entry names (don’t treat e.g. control characters specially)
-o like -l, but do not list group information
-p, --indicator-style=slash
append / indicator to directories
-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 the allocated size of each file, in blocks
-S sort by file size
--sort=WORD
sort by WORD instead of name: none -U, extension -X, size -S, time -t, version -v
--time=WORD
with -l, show time as WORD instead of modification time: atime -u, access -u, use -u, ctime -c, or status -c; use
specified time as sort key if --sort=time
--time-style=STYLE
with -l, 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 natural sort of (version) numbers within text
-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.
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).
語 法:ls [-1aAbBcCdDfFgGhHiklLmnNopqQrRsStuUvxX][-I <範本樣式>][-T <跳格字數>][-w <每列字符數>][–block-size=<區塊大小>][–color=<使用時機>][–format=<列表格式>][–full-time][–help][–indicator-style=<標註樣式>][–quoting-style=<引號樣式>][–show-control-chars][–sort=<排序方式>][–time=<時間戳記>][–version][文件或目錄…]
補充說明:執行ls指令可列出目錄的內容,包括文件和子目錄的名稱。
參 數:
-1 每列僅顯示一個文件或目錄名稱。
-a或–all 下所有文件和目錄。
-A或–almost-all 顯示所有文件和目錄,但不顯示現行目錄和上層目錄。
-b或–escape 顯示脫離字符。
-B或–ignore-backups 忽略備份文件和目錄。
-c 以更改時間排序,顯示文件和目錄。
-C 以又上至下,從左到右的直行方式顯示文件和目錄名稱。
-d或–directory 顯示目錄名稱而非其內容。
-D或–dired 用Emacs的模式產生文件和目錄列表。
-f 此參數的效果和同時指定”aU”參數相同,並關閉”lst”參數的效果。
-F或–classify 在執行文件,目錄,Socket,符號連接,管道名稱後面,各自加上”*”,”/”,”=”,”@”,”|”號。
-g 次參數將忽略不予處理。
-G或–no-group 不顯示羣組名稱。
-h或–human-readable 用”K”,”M”,”G”來顯示文件和目錄的大小。
-H或–si 此參數的效果和指定”-h”參數類似,但計算單位是1000Bytes而非1024Bytes。
-i或–inode 顯示文件和目錄的inode編號。
-I<範本樣式>或–ignore=<範本樣式> 不顯示符合範本樣式的文件或目錄名稱。
-k或–kilobytes 此參數的效果和指定”block-size=1024”參數相同。
-l 使用詳細格式列表。
-L或–dereference 如遇到性質爲符號連接的文件或目錄,直接列出該連接所指向的原始文件或目錄。
-m 用”,”號區隔每個文件和目錄的名稱。
-n或–numeric-uid-gid 以用戶識別碼和羣組識別碼替代其名稱。
-N或–literal 直接列出文件和目錄名稱,包括控制字符。
-o 此參數的效果和指定”-l” 參數類似,但不列出羣組名稱或識別碼。
-p或–file-type 此參數的效果和指定”-F”參數類似,但不會在執行文件名稱後面加上”*”號。
-q或–hide-control-chars 用”?”號取代控制字符,列出文件和目錄名稱。
-Q或–quote-name 把文件和目錄名稱以”“號標示起來。
-r或–reverse 反向排序。
-R或–recursive 遞歸處理,將指定目錄下的所有文件及子目錄一併處理。
-s或–size 顯示文件和目錄的大小,以區塊爲單位。
-S 用文件和目錄的大小排序。
-t 用文件和目錄的更改時間排序。
-T<跳格字符>或–tabsize=<跳格字數> 設置跳格字符所對應的空白字符數。
-u 以最後存取時間排序,顯示文件和目錄。
-U 列出文件和目錄名稱時不予排序。
-v 文件和目錄的名稱列表以版本進行排序。
-w<每列字符數>或–width=<每列字符數> 設置每列的最大字符數。
-x 以從左到右,由上至下的橫列方式顯示文件和目錄名稱。
-X 以文件和目錄的最後一個擴展名排序。
–block-size=<區塊大小> 指定存放文件的區塊大小。
–color=<列表格式> 培植文件和目錄的列表格式。
–full-time 列出完整的日期與時間。
–help 在線幫助。
–indicator-style=<標註樣式> 在文件和目錄等名稱後面加上標註,易於辨識該名稱所屬的類型。
–quoting-syte=<引號樣式> 把文件和目錄名稱以指定的引號樣式標示起來。
–show-control-chars 在文件和目錄列表時,使用控制字符。
–sort=<排序方式> 配置文件和目錄列表的排序方式。
–time=<時間戳記> 用指定的時間戳記取代更改時間。
–version 顯示版本信息。
ls 列出當前目錄的文件 不包括隱藏文件
[root@guofeng ~]# ls
anaconda-ks.cfg dump.rdb EOF install.log install.log.syslog
[root@guofeng ~]#
ll 顯示文件詳細信息 這個命令是別名出來的 alias
[root@guofeng ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@guofeng ~]#
[root@guofeng ~]# ll
total 64
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 337 Jun 6 02:29 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
[root@guofeng ~]# ls -l 相同的效果
total 64
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 337 Jun 6 02:29 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
[root@guofeng ~]#
ls -la 顯示隱藏文件,包括當前目錄和父級目錄
[root@guofeng ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc dump.rdb install.log .lesshst .rediscli_history .tcshrc .xauthIRKeMj
.. .bash_history .bash_profile .cshrc EOF install.log.syslog .mysql_history .rnd .viminfo .xauthMq7kGq
[root@guofeng ~]# ls -al
total 144
dr-xr-x---. 2 root root 4096 Jun 6 02:29 .
dr-xr-xr-x. 24 root root 4096 Jun 5 23:42 ..
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-------. 1 root root 14622 Jun 6 06:17 .bash_history
-rw-r--r--. 1 root root 18 May 20 2009 .bash_logout
-rw-r--r--. 1 root root 176 May 20 2009 .bash_profile
-rw-r--r--. 1 root root 176 Sep 22 2004 .bashrc
-rw-r--r--. 1 root root 100 Sep 22 2004 .cshrc
-rw-r--r-- 1 root root 337 Jun 6 02:29 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
-rw-------. 1 root root 71 May 18 07:30 .lesshst
-rw------- 1 root root 369 May 22 05:47 .mysql_history
-rw-r--r-- 1 root root 911 Jun 6 02:16 .rediscli_history
-rw-------. 1 root root 1024 Nov 10 2014 .rnd
-rw-r--r--. 1 root root 129 Dec 3 2004 .tcshrc
-rw------- 1 root root 9924 May 25 01:20 .viminfo
-rw-------. 1 root root 54 May 6 20:21 .xauthIRKeMj
-rw-------. 1 root root 66 Sep 5 2015 .xauthMq7kGq
[root@guofeng ~]#
ls -Al 列出所有文件,排除當前目錄 .”和“父目錄 ..”之外的所有文件,包括隱藏文件
[root@guofeng ~]# ls -Al
total 136
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-------. 1 root root 14622 Jun 6 06:17 .bash_history
-rw-r--r--. 1 root root 18 May 20 2009 .bash_logout
-rw-r--r--. 1 root root 176 May 20 2009 .bash_profile
-rw-r--r--. 1 root root 176 Sep 22 2004 .bashrc
-rw-r--r--. 1 root root 100 Sep 22 2004 .cshrc
-rw-r--r-- 1 root root 337 Jun 6 02:29 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
-rw-------. 1 root root 71 May 18 07:30 .lesshst
-rw------- 1 root root 369 May 22 05:47 .mysql_history
-rw-r--r-- 1 root root 911 Jun 6 02:16 .rediscli_history
-rw-------. 1 root root 1024 Nov 10 2014 .rnd
-rw-r--r--. 1 root root 129 Dec 3 2004 .tcshrc
-rw------- 1 root root 9924 May 25 01:20 .viminfo
-rw-------. 1 root root 54 May 6 20:21 .xauthIRKeMj
-rw-------. 1 root root 66 Sep 5 2015 .xauthMq7kGq
[root@guofeng ~]#
ls –author -l 列出文件的創建者
[root@guofeng ~]# ls --author -l
total 64
-rw-------. 1 root root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root root 337 Jun 6 02:29 dump.rdb
-rw-r--r-- 1 root root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root root 9154 Nov 8 2014 install.log.syslog
[root@guofeng ~]#
ls –block-size=(M|K) -l 以文件的大小類型展示
[root@guofeng ~]# ls --block-size=M -l
total 1M
-rw-------. 1 root root 1M Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0M Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 1M Jun 6 02:29 dump.rdb
-rw-r--r-- 1 root root 0M May 17 07:00 EOF
-rw-r--r--. 1 root root 1M Nov 8 2014 install.log
-rw-r--r--. 1 root root 1M Nov 8 2014 install.log.syslog
[root@guofeng ~]# ls --block-size=K -l
total 64K
-rw-------. 1 root root 3K Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0K Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 1K Jun 6 02:29 dump.rdb
-rw-r--r-- 1 root root 0K May 17 07:00 EOF
-rw-r--r--. 1 root root 39K Nov 8 2014 install.log
-rw-r--r--. 1 root root 9K Nov 8 2014 install.log.syslog
[root@guofeng ~]#
ls -cl 以文件名字排序
[root@guofeng ~]# ls -cl
total 64
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 337 Jun 6 02:29 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
ls -ctl 以最近修改文件排序
[root@guofeng ~]# ls -ctl
total 64
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 337 Jun 6 02:29 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog