每天一个命令(2)(ls - list directory contents) 5 分钟完成

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章