ls

列出有关文件及目录的信息.

语法

  ls [Options]... [File]...

选项




      如果没有-cftuSUX或--sort,则按字母顺序对文件进行排序

  -a, --all                  all列出所有文件及目录,包括以点开头的文件及目录 .

  -A, --almost-all           列出所有文件及目录,包括以点开头的文件及目录。
                             除了.和..

  -b, --escape              将文件中的不可输出的字符以反斜线“”加字符编码的方式输出

      --block-size=SIZE      使用SIZE-byte 块

  -B, --ignore-backups       不列出以〜结尾的隐含条目

  -c                         按更改时间排序

  -C                         按列列出文件及目录

      --color[=WHEN]         控制是否使用颜色来区分文件类型

  -d, --directory            列出目录文件

  -D, --dired                生成为Emacs的dired模式设计的输出

  -f                         不排序,启用-aU,禁用-lst

  -F, --classify             在每个输出项后追加文件的类型标识符(*/=@|)

      --format=WORD          Across -x, commas -m, horizontal -x, long -l,
                             single-column -1, verbose -l, vertical -C

      --full-time            列出完整日期和时间

  -g                         (忽略)

  -G, --no-group             禁止显示组信息

  -h, --human-readable       人类可读格式的打印尺寸 (如, 1K 234M 2G)
  -H, --si                   同si,但使用1000而不是1024

      --indicator-style=WORD 将带有样式字的指示符追加到文件及目录名称:
                             none (default), classify (-F), file-type (-p)

  -i, --inode                打印每个文件的索引号

  -I, --ignore=PATTERN       不列出与shell PATTERN匹配的隐含文件及目录

  -k, --kilobytes            Like --block-size=1024

  -l                         使用长列表格式

  -L, --dereference          引用符号链接指向的列表

  -m                         使用逗号分隔文件及目录列表填充宽度

  -n, --numeric-uid-gid      列出数字UID和GID而不是名称

  -N, --literal               打印原始名称

  -o                         使用长列表格式而不使用组信息

  -p, --file-type            将指示符 (/=@|)中的一个附加到文件及目录

  -q, --hide-control-chars   打印吗?而不是非图形字符

      --show-control-chars   按原样(默认)显示非图形字符

  -Q, --quote-name           用双引号将文件及目录名括起来
      --quoting-style=WORD   使用引用样式WORD的名称:
                             literal, shell, shell-always, c, escape

  -r, --reverse              反向顺序排序

  -R, --recursive            子目录递归

  -s, --size                 每个文件的打印大小,以块为单位

  -S                         按文件大小排序

      --sort=WORD            time -t, version -v, status -c 
                             size -S, extension -X, none -U
                             atime -u, access -u, use -u
                             
      --time=WORD              时间显示为WORD而不是修改时间:
                               atime, access, use, ctime or status; 
                               also use this as a sort key if --sort=time

  -t                         按修改时间排序

  -T, --tabsize=COLS         假设tab停在每个COLS

  -u                         按上次访问时间排序,也可以使用它作为排序键; with -l: show atime

  -U                         不排序;

  -v                         按版本排序

  -w, --width=COLS           假定屏幕宽度而不是当前值

  -x                         list entries by lines instead of by columns

  -X                         列表按行而不是列

  -1                         列出每行一个文件

      --help                 显示帮助并退出

      --version              输出版本信息并退出

例子

列出你的主目录的内容

$ ls ~

以垂直列表方式列出所有内容:



$ ls -al

total 109
drwxr-xr-x 18 root root 4096 Jun 9 21:12 ./
drwxr-xr-x 18 root root 4096 Jun 9 21:12 ../
drwxr-xr-x 2 root root 4096 Jun 9 21:14 bin/
drwxr-xr-x 3 root root 1024 Jun 9 20:32 boot/
drwxr-xr-x 6 root root 36864 Jul 12 10:26 dev/
drwxr-xr-x 34 root root 4096 Jul 12 10:25 etc/

列出当前目录中的目录

$ ls -d */

列出所有子目录:

 $ ls *

列出所有文件,每行一个,包括子目录 - 使用find

$ find ~/Documents/ -type f

ls的默认行为是仅将颜色控制代码传递给tty输出–color = auto。
要将输出通过颜色代码输出到第二个命令,然后设置–color = always

$ ls -lAXh --color=auto|less -R

影响ls的环境变量列表(颜色,列宽,块大小等)

ls 命令实例:

linux命令:ls -al --time-style=+%D| grep `date +%D` +%D` `date grep --time-style=+%D| -al ls ls -al --time-style=+%D| grep `date +%D`rootopen.com
linux命令:ls -al --time-style=+%D| grep `date +%D` +%D` `date grep --time-style=+%D| -al ls ls -al --time-style=+%D| grep `date +%D`rootopen.com
2019-07-09 20:54:56

linux命令:lsof -i -nlP | awk '{print $9, $8, $1}' | sed 's/.*://' | sort -u -u sort | 's/.*://' sed | $1}' $8, $9, '{print awk | -nlP -i lsof lsof -i -nlP | awk '{print $9, $8, $1}' | sed 's/.*://' | sort -urootopen.com
linux命令:lsof -i -nlP | awk '{print $9, $8, $1}' | sed 's/.*://' | sort -u -u sort | 's/.*://' sed | $1}' $8, $9, '{print awk | -nlP -i lsof lsof -i -nlP | awk '{print $9, $8, $1}' | sed 's/.*://' | sort -urootopen.com
2019-03-23 19:15:55

linux命令:ls -sSh /path | head head | /path -sSh ls ls -sSh /path | headrootopen.com
linux命令:ls -sSh /path | head head | /path -sSh ls ls -sSh /path | headrootopen.com
2019-02-12 21:11:04

linux命令:ls | perl -ne 'chomp; $f=$_; tr/A-Z/a-z/; s/(?<![.'"'"'])\b\w/\u$&/g; print qq{mv "$f" "$_"\n}' "$_"\n}' "$f" qq{mv print s/(?<![.'"'"'])\b\w/\u$&/g; tr/A-Z/a-z/; $f=$_; 'chomp; -ne perl | ls ls | perl -ne 'chomp; $f=$_; tr/A-Z/a-z/; s/(?<![.'"'"'])\b\w/\u$&/g; print qq{mv "$f" "$_"\n}'rootopen.com
linux命令:ls | perl -ne 'chomp; $f=$_; tr/A-Z/a-z/; s/(?<![.'"'"'])\b\w/\u$&/g; print qq{mv "$f" "$_"\n}' "$_"\n}' "$f" qq{mv print s/(?<![.'"'"'])\b\w/\u$&/g; tr/A-Z/a-z/; $f=$_; 'chomp; -ne perl | ls ls | perl -ne 'chomp; $f=$_; tr/A-Z/a-z/; s/(?<![.'"'"'])\b\w/\u$&/g; print qq{mv "$f" "$_"\n}'rootopen.com
2018-12-08 16:58:57

linux命令:lsusb lsusb lsusbrootopen.com
linux命令:lsusb lsusb lsusbrootopen.com
2018-09-11 09:55:30

linux命令:lsof -u tecmint tecmint -u lsof lsof -u tecmintrootopen.com
linux命令:lsof -u tecmint tecmint -u lsof lsof -u tecmintrootopen.com
2018-09-11 09:55:30

linux命令:lscpu lscpu lscpurootopen.com
linux命令:lscpu lscpu lscpurootopen.com
2018-09-11 09:55:30

linux命令:ls -l file1 file1 -l ls ls -l file1rootopen.com
linux命令:ls -l file1 file1 -l ls ls -l file1rootopen.com
2018-09-11 09:55:30

linux命令:lsscsi lsscsi lsscsirootopen.com
linux命令:lsscsi lsscsi lsscsirootopen.com
2018-08-29 21:54:20

linux命令:lspci -v -v lspci lspci -vrootopen.com
linux命令:lspci -v -v lspci lspci -vrootopen.com
2018-08-29 21:52:41

linux命令:lspci lspci lspcirootopen.com
linux命令:lspci lspci lspcirootopen.com
2018-08-29 21:51:51

linux命令:lsusb lsusb lsusb rootopen.com
linux命令:lsusb lsusb lsusb rootopen.com
2018-08-29 21:51:01

linux命令:lsblk -a -a lsblk lsblk -a rootopen.com
linux命令:lsblk -a -a lsblk lsblk -a rootopen.com
2018-08-29 21:50:27

linux命令:lsblk lsblk lsblkrootopen.com
linux命令:lsblk lsblk lsblkrootopen.com
2018-08-29 21:49:35

linux命令:lscpu lscpu lscpurootopen.com
linux命令:lscpu lscpu lscpurootopen.com
2018-08-29 21:48:03

linux命令:ls -d $PWD/* $PWD/* -d ls ls -d $PWD/*rootopen.com
linux命令:ls -d $PWD/* $PWD/* -d ls ls -d $PWD/*rootopen.com
2018-08-16 21:49:17

linux命令:ls -d */ */ -d ls ls -d */rootopen.com
linux命令:ls -d */ */ -d ls ls -d */rootopen.com
2018-08-16 21:48:48

linux命令:ls > out.txt out.txt > ls ls > out.txtrootopen.com
linux命令:ls > out.txt out.txt > ls ls > out.txtrootopen.com
2018-08-16 21:48:20

linux命令:ls * .txt .txt * ls ls * .txtrootopen.com
linux命令:ls * .txt .txt * ls ls * .txtrootopen.com
2018-08-16 21:47:58

linux命令:ls -R -R ls ls -Rrootopen.com
linux命令:ls -R -R ls ls -Rrootopen.com
2018-08-16 21:47:38

linux命令:ls * * ls ls *rootopen.com
linux命令:ls * * ls ls *rootopen.com
2018-08-16 21:47:21

linux命令:ls -S -S ls ls -Srootopen.com
linux命令:ls -S -S ls ls -Srootopen.com
2018-08-16 21:47:02

linux命令:ls -t -t ls ls -trootopen.com
linux命令:ls -t -t ls ls -trootopen.com
2018-08-16 21:46:36

linux命令:ls -la -la ls ls -larootopen.com
linux命令:ls -la -la ls ls -larootopen.com
2018-08-16 21:46:05

linux命令:ls -a -a ls ls -arootopen.com
linux命令:ls -a -a ls ls -arootopen.com
2018-08-16 21:45:45

linux命令:ls -l -l ls ls -lrootopen.com
linux命令:ls -l -l ls ls -lrootopen.com
2018-08-16 21:45:27

linux命令:ls~ ls~ ls~rootopen.com
linux命令:ls~ ls~ ls~rootopen.com
2018-08-16 21:45:00

linux命令:ls .. .. ls ls ..rootopen.com
linux命令:ls .. .. ls ls ..rootopen.com
2018-08-16 21:44:38

linux命令:ls / / ls ls /rootopen.com
linux命令:ls / / ls ls /rootopen.com
2018-08-16 21:44:14

linux命令:ls /home/user/Documents/Books /home/user/Documents/Books ls ls /home/user/Documents/Booksrootopen.com
linux命令:ls /home/user/Documents/Books /home/user/Documents/Books ls ls /home/user/Documents/Booksrootopen.com
2018-08-16 21:43:37

linux命令:ls Documents/Books Documents/Books ls ls Documents/Booksrootopen.com
linux命令:ls Documents/Books Documents/Books ls ls Documents/Booksrootopen.com
2018-08-16 21:42:38

linux命令:ls -lt -lt ls ls -ltrootopen.com
linux命令:ls -lt -lt ls ls -ltrootopen.com
2018-08-16 21:34:55

linux命令:ls -l | grep rwxrwxrwx rwxrwxrwx grep | -l ls ls -l | grep rwxrwxrwxrootopen.com
linux命令:ls -l | grep rwxrwxrwx rwxrwxrwx grep | -l ls ls -l | grep rwxrwxrwxrootopen.com
2018-08-11 22:32:17

linux命令:lspci -vv -vv lspci lspci -vvrootopen.com
linux命令:lspci -vv -vv lspci lspci -vvrootopen.com
2018-01-27 01:05:48

linux命令:lspci | grep Ether | awk '{ VAR=$1; split(VAR,ARR,"."); count[ARR[1]]++; LINE=$0; split(LINE,LINEARR,":"); LINECOUNT[ARR[1]]=LINEARR[3]; } END { for(i in count) { printf("PCI address: %s\nPorts: %d\nCard Type: %s\n", i, count[i], LINECOUNT[i]) } }' }' } LINECOUNT[i]) count[i], i, %s\n", Type: %d\nCard %s\nPorts: address: printf("PCI { count) in for(i { END } LINECOUNT[ARR[1]]=LINEARR[3]; split(LINE,LINEARR,":"); LINE=$0; count[ARR[1]]++; split(VAR,ARR,"."); VAR=$1; '{ awk | Ether grep | lspci lspci | grep Ether | awk '{ VAR=$1; split(VAR,ARR,"."); count[ARR[1]]++; LINE=$0; split(LINE,LINEARR,":"); LINECOUNT[ARR[1]]=LINEARR[3]; } END { for(i in count) { printf("PCI address: %s\nPorts: %d\nCard Type: %s\n", i, count[i], LINECOUNT[i]) } }'rootopen.com
linux命令:lspci | grep Ether | awk '{ VAR=$1; split(VAR,ARR,"."); count[ARR[1]]++; LINE=$0; split(LINE,LINEARR,":"); LINECOUNT[ARR[1]]=LINEARR[3]; } END { for(i in count) { printf("PCI address: %s\nPorts: %d\nCard Type: %s\n", i, count[i], LINECOUNT[i]) } }' }' } LINECOUNT[i]) count[i], i, %s\n", Type: %d\nCard %s\nPorts: address: printf("PCI { count) in for(i { END } LINECOUNT[ARR[1]]=LINEARR[3]; split(LINE,LINEARR,":"); LINE=$0; count[ARR[1]]++; split(VAR,ARR,"."); VAR=$1; '{ awk | Ether grep | lspci lspci | grep Ether | awk '{ VAR=$1; split(VAR,ARR,"."); count[ARR[1]]++; LINE=$0; split(LINE,LINEARR,":"); LINECOUNT[ARR[1]]=LINEARR[3]; } END { for(i in count) { printf("PCI address: %s\nPorts: %d\nCard Type: %s\n", i, count[i], LINECOUNT[i]) } }'rootopen.com
2018-06-03 03:22:48

linux命令:lsof -i -n | grep ESTABLISHED ESTABLISHED grep | -n -i lsof lsof -i -n | grep ESTABLISHEDrootopen.com
linux命令:lsof -i -n | grep ESTABLISHED ESTABLISHED grep | -n -i lsof lsof -i -n | grep ESTABLISHEDrootopen.com
2018-04-23 19:31:48

linux命令:ls -dF `find . -maxdepth 1 \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print` -print` \) \) -100 -perm -o -10 -perm \( -o -1 -perm \( 1 -maxdepth . `find -dF ls ls -dF `find . -maxdepth 1 \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print`rootopen.com
linux命令:ls -dF `find . -maxdepth 1 \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print` -print` \) \) -100 -perm -o -10 -perm \( -o -1 -perm \( 1 -maxdepth . `find -dF ls ls -dF `find . -maxdepth 1 \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print`rootopen.com
2018-01-14 17:22:48

linux命令:ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' '\''s/-/|/'\'' -e /'\'' '\''s/^/ -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/:$//'\'' -e sed | : grep | -R ls ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''rootopen.com
linux命令:ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' '\''s/-/|/'\'' -e /'\'' '\''s/^/ -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/:$//'\'' -e sed | : grep | -R ls ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''rootopen.com
2018-01-02 02:01:48

linux命令:ls -la | awk '{print $5, " " ,$9}' | sort -rn -rn sort | ,$9}' " " $5, '{print awk | -la ls ls -la | awk '{print $5, " " ,$9}' | sort -rnrootopen.com
linux命令:ls -la | awk '{print $5, " " ,$9}' | sort -rn -rn sort | ,$9}' " " $5, '{print awk | -la ls ls -la | awk '{print $5, " " ,$9}' | sort -rnrootopen.com
2018-01-24 14:14:48

linux命令:ls -la | awk '$3 == "oracle" || $3 == "root" {print $9}' $9}' {print "root" == $3 || "oracle" == '$3 awk | -la ls ls -la | awk '$3 == "oracle" || $3 == "root" {print $9}'rootopen.com
linux命令:ls -la | awk '$3 == "oracle" || $3 == "root" {print $9}' $9}' {print "root" == $3 || "oracle" == '$3 awk | -la ls ls -la | awk '$3 == "oracle" || $3 == "root" {print $9}'rootopen.com
2018-02-11 13:08:48

linux命令:ls -al /proc/<PID>/fd /proc/<PID>/fd -al ls ls -al /proc/<PID>/fdrootopen.com
linux命令:ls -al /proc/<PID>/fd /proc/<PID>/fd -al ls ls -al /proc/<PID>/fdrootopen.com
2018-03-05 16:55:48

linux命令:ls -l | egrep ^d ^d egrep | -l ls ls -l | egrep ^drootopen.com
linux命令:ls -l | egrep ^d ^d egrep | -l ls ls -l | egrep ^drootopen.com
2018-05-15 01:54:48

linux命令:lsof -u www-data www-data -u lsof lsof -u www-datarootopen.com
linux命令:lsof -u www-data www-data -u lsof lsof -u www-datarootopen.com
2018-05-18 21:07:48

linux命令:ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' ",k);print}' '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o awk | -l ls ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'rootopen.com
linux命令:ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' ",k);print}' '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o awk | -l ls ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'rootopen.com
2018-02-24 16:17:48

linux命令:ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' 's/-/|/' -e /' 's/^/ -e 's/[^-][^\/]*\//--/g' -e 's/:$//' -e sed | ":$" grep | -R ls ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'rootopen.com
linux命令:ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' 's/-/|/' -e /' 's/^/ -e 's/[^-][^\/]*\//--/g' -e 's/:$//' -e sed | ":$" grep | -R ls ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'rootopen.com
2018-05-04 19:27:48

linux命令:ls -F | grep '\''\*'\'' | sed '\''s/\*$//'\ '\''s/\*$//'\ sed | '\''\*'\'' grep | -F ls ls -F | grep '\''\*'\'' | sed '\''s/\*$//'\rootopen.com
linux命令:ls -F | grep '\''\*'\'' | sed '\''s/\*$//'\ '\''s/\*$//'\ sed | '\''\*'\'' grep | -F ls ls -F | grep '\''\*'\'' | sed '\''s/\*$//'\rootopen.com
2017-12-30 21:26:48

linux命令:ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate" appropriate" "nothing -v grep | 2>/dev/null whatis -l1 xargs | /bin -1 ls ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate"rootopen.com
linux命令:ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate" appropriate" "nothing -v grep | 2>/dev/null whatis -l1 xargs | /bin -1 ls ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate"rootopen.com
2018-05-05 01:59:48

linux命令:ls -1 . dir2 dir3|sort|uniq -d -d dir3|sort|uniq dir2 . -1 ls ls -1 . dir2 dir3|sort|uniq -drootopen.com
linux命令:ls -1 . dir2 dir3|sort|uniq -d -d dir3|sort|uniq dir2 . -1 ls ls -1 . dir2 dir3|sort|uniq -drootopen.com
2018-05-19 01:43:48

linux命令:ls -lrt -lrt ls ls -lrtrootopen.com
linux命令:ls -lrt -lrt ls ls -lrtrootopen.com
2018-04-23 17:53:48

linux命令:ls -l !* | /usr/bin/grep '^d' '^d' /usr/bin/grep | !* -l ls ls -l !* | /usr/bin/grep '^d'rootopen.com
linux命令:ls -l !* | /usr/bin/grep '^d' '^d' /usr/bin/grep | !* -l ls ls -l !* | /usr/bin/grep '^d'rootopen.com
2018-04-27 07:52:48

Linux的Bash命令行(A-Z排序)