ls

Linux ls命令用于显示指定工作目录下之内容(列出目前工作目录所含之文件及子目录)。

语法

 ls [-alrtAFR] [name...]

参数 :

-a 显示所有文件及目录 (ls内定将文件名或目录名称开头为"."的视为隐藏档,不会列出)
-l 除文件名称外,亦将文件型态、权限、拥有者、文件大小等资讯详细列出
-r 将文件以相反次序显示(原定依英文字母次序)
-t 将文件依建立时间之先后次序列出
-A 同 -a ,但不列出 "." (目前目录)".." (父目录)
-F 在列出的文件名称后加一符号;例如可执行档则加 "*", 目录则加 "/"
-R 若目录下有文件,则以下之文件亦皆依序列出
#ll == ls -l
#ll 命令列出的信息更加详细,有时间,是否可读写等信息
#ll会列出该文件下的所有文件信息,包括隐藏的文件,
[root@ c7-41 mnt]# ll
total 0
-rw-rw-r-- 1 root root 0 May  4 09:56 file1
-r---w-r-- 1 root root 0 May  4 09:56 file2
-rw-rw-r-- 1 root root 0 May  4 09:56 file3
-rw-r----- 1 root root 0 May  4 10:08 student
-rw-r----- 1 root root 0 May  4 10:08 westos
#ls 只列出文件名或目录名
[root@ c7-41 mnt]# ls
file1  file2  file3  student  westos
#ls -l只列出显式文件,说明这两个命令还是不等同的!
[root@ c7-41 mnt]# ls -l
total 0
-rw-rw-r-- 1 root root 0 May  4 09:56 file1
-r---w-r-- 1 root root 0 May  4 09:56 file2
-rw-rw-r-- 1 root root 0 May  4 09:56 file3
-rw-r----- 1 root root 0 May  4 10:08 student
-rw-r----- 1 root root 0 May  4 10:08 westos

ls

#-a 列出目录下的所有文件,包括以 . 开头的隐含文件。
[root@ c7-41 mnt]# ls -a   
.  ..  file1  file2  file3  student  westos

#-b 把文件名中不可输出的字符用反斜杠加字符编号(就象在C语言里一样)的形式列出。
[root@ c7-41 mnt]# ls -b
file1  file2  file3  student  westos

#-c 输出文件的 i 节点的修改时间,并以此排序。
[root@ c7-41 mnt]# ls -c
westos  student  file1  file2  file3

#-d 将目录象文件一样显示,而不是显示其下的文件。
[root@ c7-41 mnt]# ls -d
.
#-i 输出文件的 i 节点的索引信息。
[root@ c7-41 mnt]# ls -i
289 file1  298 file2  309 file3  311 student  312 westos

#-l 列出文件的详细信息
[root@ c7-41 mnt]# ls -l
total 0
-rw-rw-r-- 1 root root 0 May  4 09:56 file1
-r---w-r-- 1 root root 0 May  4 09:56 file2
-rw-rw-r-- 1 root root 0 May  4 09:56 file3
-rw-r----- 1 root root 0 May  4 10:08 student
-rw-r----- 1 root root 0 May  4 10:08 westos

#-m 横向输出文件名,并以“,”作分格符。
[root@ c7-41 mnt]# ls -m
file1, file2, file3, student, westos

#-n 用数字的 UID,GID 代替名称。
[root@ c7-41 mnt]# ls -n student  #sudent 为uid
-rw-r----- 1 0 0 0 May  4 10:08 student

#显示文件的除组信息外的详细信息。
[root@ c7-41 mnt]# ls -o
total 0
-rw-rw-r-- 1 root 0 May  4 09:56 file1
-r---w-r-- 1 root 0 May  4 09:56 file2
-rw-rw-r-- 1 root 0 May  4 09:56 file3
-rw-r----- 1 root 0 May  4 10:08 student
-rw-r----- 1 root 0 May  4 10:08 westos
#-p -F 在每个文件名后附上一个字符以说明该文件的类型,“*”表示可执行的普通文件;“/”表示目录;“@”表示符号链接;“|”表示FIFOs;“=”表示套接字(sockets)
[root@ c7-41 mnt]# ls -p -F /
bin@   dev/  home/  lib64@  mnt/  proc/  run/   srv/  tmp/  var/
boot/  etc/  lib@   media/  opt/  root/  sbin@  sys/  usr/

#-q 用?代替不可输出的字符。
[root@ c7-41 mnt]# ls -q
file1  file2  file3  student  westos

#-r 对目录反向排序。
[root@ c7-41 mnt]# ls -r
westos  student  file3  file2  file1

#在每个文件名前输出该文件的大小
[root@ c7-41 mnt]# ls -s
total 0
0 file1  0 file2  0 file3  0 student  0 westos

说明以最近修改的日期进行排序!
#-u 以文件上次被访问的时间排序。
[root@ c7-41 mnt]# ls -u
westos  student  file1  file2  file3

#-A 显示除 “.”和“..”外的所有文件。
[root@ c7-41 mnt]# ls -A
file1  file2  file3  student  westos

#-B 不输出以 “~”结尾的备份文件。
[root@ c7-41 mnt]# ls -B
file1  file2  file3  student  westos

#-L 列出链接文件名而不是链接到的文件。
[root@ c7-41 mnt]# ls -L
file1  file2  file3  student  westos

#-N 不限制文件长度。
[root@ c7-41 mnt]# ls -N
file1  file2  file3  student  westos

#-Q 把输出的文件名用双引号括起来。
[root@ c7-41 mnt]# ls -Q
"file1"  "file2"  "file3"  "student"  "westos"

#-R 列出所有子目录下的文件。
[root@ c7-41 mnt]# ls -R
.:
file1  file2  file3  student  westos

#-S 以文件大小排序。
[root@ c7-41 mnt]# ls -S
file1  file2  file3  student  westos

#-X 以文件的扩展名(最后一个 . 后的字符)排序。
[root@ c7-41 mnt]# ls -X
file1  file2  file3  student  westos

#-1 一行只输出一个文件。
[root@ c7-41 mnt]# ls -1
file1
file2
file3
student
westos

#--color=no 不显示彩色文件名
[root@ c7-41 mnt]# ls --color=no
file1  file2  file3  student  westos
#--help 在标准输出上显示帮助信息。
[root@ c7-41 mnt]# ls --help

#--version在标准输出上输出版本信息并退出
[root@ c7-41 mnt]# ls --version
ls (GNU coreutils) 8.22

只列出子目录
[root@ c7-41 etc]# ls -F | grep /$
abrt/
alternatives/
audisp/
audit/
bash_completion.d/
binfmt.d/
chkconfig.d/
cron.d/
cron.daily/


[root@ c7-41 etc]# ls -l | grep "^d"
drwxr-xr-x.  3 root root    101 Apr 17 14:38 abrt
drwxr-xr-x.  2 root root    261 Apr 17 16:01 alternatives
drwxr-x---.  3 root root     43 Apr 17 14:38 audisp
drwxr-x---.  3 root root     83 Apr 17 14:45 audit
drwxr-xr-x.  2 root root     79 Apr 17 16:01 bash_completion.d
drwxr-xr-x.  2 root root      6 Aug  8  2019 binfmt.d
drwxr-xr-x.  2 root root      6 Aug  4  2017 chkconfig.d
drwxr-xr-x.  2 root root     36 Apr 17 16:01 cr

计算当前目录下的文件数和目录数

[root@ c7-41 etc]# ls -l
total 1104
drwxr-xr-x.  3 root root    101 Apr 17 14:38 abrt
-rw-r--r--.  1 root root     16 Apr 17 14:40 adjtime
-rw-r--r--.  1 root root   1518 Jun  7  2013 aliases
-rw-r--r--.  1 root root  12288 Apr 17 14:45 aliases.db
drwxr-xr-x.  2 root root    261 Apr 17 16:01 alternatives

#^- 表示文件
[root@ c7-41 etc]# ls -l | grep "^-" | wc -l
95
#^d表示目录
[root@ c7-41 etc]# ls -l | grep "^d" | wc -l
79

显示彩色目录列表

打开/etc/bashrc, 加入如下一行:

alias ls=“ls --color”

下次启动bash时就可以像在Slackware里那样显示彩色的目录列表了, 其中颜色的含义如下:

  1. 蓝色–>目录

  2. 绿色–>可执行文件

  3. 红色–>压缩文件

  4. 浅蓝色–>链接文件

  5. 灰色–>其他文件

ls -tl --time-style=full-iso sshd

[root@ c7-41 etc]# ls -ctl --time-style=long-iso
total 1104
-rw-r--r--   1 root root     41 2020-05-04 08:55 subgid
----------   1 root root    436 2020-05-04 08:55 gshadow
-rw-r--r--   1 root root     21 2020-05-04 08:55 subgid-
-rw-r--r--   1 root root     41 2020-05-04 08:55 subuid
-rw-r--r--   1 root root     21 2020-05-04 08:55 subuid-
-rw-r--r--   1 root root    550 2020-05-04 08:55 group
-rw-r--r--.  1 root root    535 2020-05-04 08:55 group-
----------.  1 root root    425 2020-05-04 08:55 gshadow-
----------   1 root root    680 2020-05-04 08:55 shadow
----------.  1 root root    651 2020-05-04 08:55 shadow-
-rw-r--r--   1 root root   1062 2020-05-04 08:55 passwd
-rw-r--r--.  1 root root   1019 2020-05-04 08:55 passwd-
-rw-r--r--.  1 root root     43 2020-05-04 08:45 resolv.conf
-rw-r--r--.  1 root root      1 2020-05-04 08:45 resolv.conf.save
-rw-r--r--.  1 root root   1873 2020-04-18 10:53 profile
-rw-r--r--   1 root root      6 2020-04-17 16:22 hostname
-rw-r--r--.  1 root root  29615 2020-04-17 16:01 ld.so.cache
drwxr-xr-x.  2 root root     79 2020-04-17 16:01 bash_completion.d
drwxr-xr-x.  2 root root   4096 2020-04-17 16:01 profile.d
drwxr-xr-x.  6 root root   4096 2020-04-17 16:01 sysconfig
drwxr-xr-x.  2 root root     36 2020-04-17 16:01 cron.d
drwxr-xr-x.  2 root root    254 2020-04-17 16:01 rpm
drwxr-xr-x.  3 root root     52 2020-04-17 16:01 ntp
-rw-r--r--.  1 root root   2000 2020-04-17 16:01 ntp.conf
-rw-r--r--.  1 root root   1982 2020-04-17 16:01 vimrc
drwxr-xr-x.  2 root root    261 2020-04-17 16:01 alternatives
drwxr-xr-x.  2 root root    204 2020-04-17 16:00 yum.repos.d
-rw-r--r--.  1 root root   4479 2020-04-17 15:59 wgetrc
drwxr-xr-x.  5 root root     81 2020-04-17 15:58 selinux
-rw-r--r--.  1 root root  12288 2020-04-17 14:45 aliases.db
drwxr-xr-x.  2 root root    225 2020-04-17 14:45 ssh
drwxr-x---.  3 root root     83 2020-04-17 14:45 audit
drwxr-xr-x.  3 root root     54 2020-04-17 14:45 udev
-rw-------.  1 root root      0 2020-04-17 14:41 crypttab
-rw-r--r--.  1 root root    465 2020-04-17 14:41 fstab
lrwxrwxrwx.  1 root root     17 2020-04-17 14:41 mtab -> /proc/self/mounts
-rw-r--r--.  1 root root     16 2020-04-17 14:40 adjtime
-rw-r--r--.  1 root root     19 2020-04-17 14:40 locale.conf
lrwxrwxrwx.  1 root root     35 2020-04-17 14:40 localtime -> ../usr/share/zoneinfo/Asia/Shanghai
-rw-r--r--.  1 root root     37 2020-04-17 14:40 vconsole.conf
drwxr-xr-x.  2 root root   4096 2020-04-17 14:40 pam.d
drwxr-xr-x.  2 root root     44 2020-04-17 14:40 default
drwx------.  2 root root    182 2020-04-17 14:38 grub.d
drwxr-xr-x.  3 root root     41 2020-04-17 14:38 latrace.d
-rw-r--r--.  1 root root    112 2020-04-17 14:38 e2fsck.conf
-rw-r--r--.  1 root root    936 2020-04-17 14:38 mke2fs.conf
-r--r-----.  1 root root   4328 2020-04-17 14:38 sudoers
drwxr-x---.  2 root root      6 2020-04-17 14:38 sudoers.d
-rw-r-----.  1 root root   1786 2020-04-17 14:38 sudo.conf
-rw-r-----.  1 root root   3181 2020-04-17 14:38 sudo-ldap.conf
drwxr-xr-x.  2 root root     42 2020-04-17 14:38 cron.daily
-rw-r--r--.  1 root root   5171 2020-04-17 14:38 man_db.conf
drwxr-xr-x.  3 root root     24 2020-04-17 14:38 kernel
drwxr-x---.  3 root root     43 2020-04-17 14:38 audisp
drwxr-xr-x.  2 root root    154 2020-04-17 14:38 postfix
drwxr-xr-x.  2 root root     24 2020-04-17 14:38 sasl2
drwxr-xr-x.  2 root root    133 2020-04-17 14:38 ld.so.conf.d
drwxr-xr-x.  2 root root     81 2020-04-17 14:38 modprobe.d
drwxr-xr-x.  6 root root    100 2020-04-17 14:38 lvm
drwxr-xr-x.  5 root root    231 2020-04-17 14:38 vmware-tools
drwxr-xr-x.  2 root root      6 2020-04-17 14:38 subversion
drwxr-xr-x.  3 root root    109 2020-04-17 14:38 tuned
-rw-r--r--.  1 root root   3232 2020-04-17 14:38 rsyslog.conf
drwxr-xr-x.  2 root root     25 2020-04-17 14:38 rsyslog.d
drwxr-xr-x.  2 root root     68 2020-04-17 14:38 logrotate.d
drwxr-xr-x. 10 root root    116 2020-04-17 14:38 pki
drwxr-x---.  7 root root    133 2020-04-17 14:38 firewalld
drwxr-xr-x.  2 root root     28 2020-04-17 14:38 plymouth
drwxr-xr-x.  3 root root    101 2020-04-17 14:38 abrt
-rw-------.  1 tss  tss    7046 2020-04-17 14:38 tcsd.conf
-rw-r--r--.  1 root root   1317 2020-04-17 14:38 ethertypes
-rw-r--r--.  1 root root    458 2020-04-17 14:38 rsyncd.conf
drwxr-xr-x.  6 root root    187 2020-04-17 14:38 libreport
drwxr-xr-x.  7 root root    134 2020-04-17 14:38 NetworkManager
drwxr-xr-x.  2 root root     33 2020-04-17 14:38 wpa_supplicant
lrwxrwxrwx.  1 root root     22 2020-04-17 14:38 grub2.cfg -> ../boot/grub2/grub.cfg
-rw-r--r--.  1 root root   7274 2020-04-17 14:38 kdump.conf
-rw-r--r--.  1 root root   5122 2020-04-17 14:38 makedumpfile.conf.sample
drwxr-x---.  4 root root     53 2020-04-17 14:38 dhcp
-rw-------.  1 root root      0 2020-04-17 14:38 cron.deny
drwxr-xr-x.  2 root root     22 2020-04-17 14:38 cron.hourly
-rw-------.  1 root root    541 2020-04-17 14:38 anacrontab
drwxr-xr-x.  2 root root      6 2020-04-17 14:38 cron.monthly
-rw-r--r--.  1 root root    451 2020-04-17 14:38 crontab
drwxr-xr-x.  2 root root      6 2020-04-17 14:38 cron.weekly
-rw-r--r--.  1 root root    216 2020-04-17 14:38 sestatus.conf
drwxr-xr-x.  2 root root     78 2020-04-17 14:38 prelink.conf.d
-rw-r--r--.  1 root root    449 2020-04-17 14:38 sysctl.conf
drwxr-xr-x.  2 root root     28 2020-04-17 14:38 sysctl.d
-rw-r--r--.  1 root root    966 2020-04-17 14:38 rwtab
drwxr-xr-x.  2 root root     23 2020-04-17 14:38 rwtab.d
-rw-r--r--.  1 root root    212 2020-04-17 14:38 statetab
drwxr-xr-x.  2 root root      6 2020-04-17 14:38 statetab.d
drwxr-xr-x.  3 root root    123 2020-04-17 14:38 ppp
-rw-r--r--.  1 root root    511 2020-04-17 14:38 inittab
-rw-r--r--.  1 root root     58 2020-04-17 14:38 networks
drwxr-xr-x.  5 root root     72 2020-04-17 14:38 polkit-1
drwxr-xr-x.  4 root root     78 2020-04-17 14:38 dbus-1
-rw-r--r--.  1 root root   1949 2020-04-17 14:38 nsswitch.conf
-rw-r--r--.  1 root root   1938 2020-04-17 14:38 nsswitch.conf.bak
-r--r--r--.  1 root root     33 2020-04-17 14:38 machine-id
drwxr-xr-x.  4 root root    151 2020-04-17 14:38 systemd
drwxr-xr-x.  2 root root      6 2020-04-17 14:38 tmpfiles.d
drwxr-xr-x.  4 root root     38 2020-04-17 14:38 xdg
drwxr-xr-x. 10 root root    127 2020-04-17 14:38 rc.d
lrwxrwxrwx.  1 root root     13 2020-04-17 14:38 rc.local -> rc.d/rc.local
drwxr-xr-x.  2 root root      6 2020-04-17 14:38 modules-load.d
drwxr-xr-x.  2 root root      6 2020-04-17 14:38 binfmt.d
drwxr-xr-x.  5 root root     57 2020-04-17 14:38 X11
drwxr-xr-x.  2 root root     23 2020-04-17 14:38 depmod.d
-rw-r--r--.  1 root root   1285 2020-04-17 14:38 dracut.conf
drwxr-xr-x.  2 root root      6 2020-04-17 14:38 dracut.conf.d
-rw-r--r--.  1 root root   2027 2020-04-17 14:38 login.defs
drwxr-xr-x.  6 root root    100 2020-04-17 14:38 yum
-rw-r--r--.  1 root root    970 2020-04-17 14:38 yum.conf
drwxr-xr-x.  2 root root      6 2020-04-17 14:38 gnupg
-rw-r--r--.  1 root root    570 2020-04-17 14:38 my.cnf
drwxr-xr-x.  2 root root     31 2020-04-17 14:38 my.cnf.d
-rw-r--r--.  1 root root   2391 2020-04-17 14:38 libuser.conf
drwxr-xr-x.  3 root root     36 2020-04-17 14:38 openldap
-rw-r--r--.  1 root root     55 2020-04-17 14:38 asound.conf
-rw-r--r--.  1 root root   1968 2020-04-17 14:38 mail.rc
-rw-r--r--.  1 root root    662 2020-04-17 14:38 logrotate.conf
lrwxrwxrwx.  1 root root     56 2020-04-17 14:38 favicon.png -> /usr/share/icons/hicolor/16x16/apps/fedora-logo-icon.png


  • 3
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云原生解决方案

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值