ls
命令说明:
查看文件与目录
语法:
ls [-aAdfFhilnrRst] 目录名称
ls [--color={never,auto,always}] 目录名称
ls [--full-time] 目录名称
参数:
-a :全部的文件,连同隐藏文件(开头为.的文件)一起列出来
-A :列出全部的文件(连同隐藏文件,但不包括.与..这两个目录)
-b :把文件名中不可输出的字符用反斜杠加字符编号的形式列出
-c :输出文件的inode的修改时间,并以此排序
-d :仅列出目录本身,而不是列出目录的文件数据
-e :输出时间的全部信息,而不是输出简略信息
-f :直接列出结果,而不进行排序(ls默认会以文件名排序)
-p -F :在每个文件名后附上一个字符以说明该文件的类型,“*”表示可执行的普通文件
“/”表示目录;“@”表示符号链接;“|”表示FIFOs ;“=”表示套接字
-h :将文件内容以较易的方式(例如GB,KB)列出来
-i :列出inode号码
-k :以k字节的形式表示文件的大小
-l :列出长数据串,包含文件的属性与权限等数据(列出文件的详细信息)
-n :列出UID及GID,而非用户与用户组的名称
-r :将输出结果反向输出
-R :连同子目录内容一起列出来
-s :在每个文件名后输出该文件的大小
-S :以文件容量大小排序,而不是用文件名排序
-t :依时间排序,不是文件名按照修改时间排序
-u :以文件上次被访问的时间排序
-L :列出链接文件名而不是链接到的文件
-N :不限制文件长度
-Q :把输出的文件名用双引号括起来
-X :以文件的扩展名排序
-1 :一行只输出一个文件
--color=never :不要依据文件特性给予颜色显示
--color=always :显示颜色
--color=auto :让系统自行依据设置来判断是否给予颜色
--full-time :以完整的时间模式(包含年、月、日、时、分)输出
--time={atime,ctime}:输出访问时间或改变权限属性时间(ctime),而非内容更改时间
命令实践:
[root@yubinghost ~]# ls /home
yubing
[root@yubinghost ~]# ls -a /home
. .. yubing
[root@yubinghost ~]# ls -a 列出全部文件,包括隐藏文件
. .bash_history .bashrc install.log.syslog .tcshrc
.. .bash_logout .cshrc o1 test.txt
anaconda-ks.cfg .bash_profile install.log oldboy.txt .viminfo
[root@yubinghost ~]# ls -A
anaconda-ks.cfg .bash_profile install.log oldboy.txt .viminfo
.bash_history .bashrc install.log.syslog .tcshrc
.bash_logout .cshrc o1 test.txt
[root@yubinghost ~]# ls -i 列出inode节点号
1267977 anaconda-ks.cfg 1267971 install.log.syslog 1267979 oldboy.txt
1267970 install.log 1267981 o1 1267982 test.txt
[root@yubinghost ~]# ls -l
total 64
-rw------- 1 root root 939 Apr 3 12:38 anaconda-ks.cfg
-rw-r--r-- 1 root root 23947 Apr 3 12:37 install.log
-rw-r--r-- 1 root root 3619 Apr 3 12:37 install.log.syslog
-rw-r--r-- 1 root root 18 Apr 5 14:43 o1
-rw-r--r-- 1 root root 0 Apr 5 14:36 oldboy.txt
-rw-r--r-- 1 root root 18 Apr 5 14:47 test.txt
[root@yubinghost ~]# ls -lr
total 64
-rw-r--r-- 1 root root 18 Apr 5 14:47 test.txt
-rw-r--r-- 1 root root 0 Apr 5 14:36 oldboy.txt
-rw-r--r-- 1 root root 18 Apr 5 14:43 o1
-rw-r--r-- 1 root root 3619 Apr 3 12:37 install.log.syslog
-rw-r--r-- 1 root root 23947 Apr 3 12:37 install.log
-rw------- 1 root root 939 Apr 3 12:38 anaconda-ks.cfg
[root@yubinghost ~]# ls --full-time 以完整的时间模式列出
total 64
-rw------- 1 root root 939 2013-04-03 12:38:00.000000000 -0400 anaconda-ks.cfg
-rw-r--r-- 1 root root 23947 2013-04-03 12:37:51.000000000 -0400 install.log
-rw-r--r-- 1 root root 3619 2013-04-03 12:37:29.000000000 -0400 install.log.syslog
-rw-r--r-- 1 root root 18 2013-04-05 14:43:32.000000000 -0400 o1
-rw-r--r-- 1 root root 0 2013-04-05 14:36:00.000000000 -0400 oldboy.txt
-rw-r--r-- 1 root root 18 2013-04-05 14:47:53.000000000 -0400 test.txt
[root@yubing etc]# ls -F 会发现目录后面加了/ 可执行文件后加了*
acpi/ dev.d/ initlog.conf mtab racoon/ shadow
adjtime dhclient-eth0.conf inittab mtools.conf rc@ shadow-
aliases dhcp6c.conf inputrc multipath.conf rc0.d@ shells
aliases.db DIR_COLORS iproute2/ netplug/ rc1.d@ skel/
alsa/ DIR_COLORS.xterm issue netplug.d/ rc2.d@ smartd.conf
alternatives/ dnsmasq.conf issue.net NetworkManager/ rc3.d@ smrsh/
anacrontab dnsmasq.d/ jwhois.conf nscd.conf rc4.d@ sound/
at.deny dumpdates krb5.conf nsswitch.conf rc5.d@ ssh/
audisp/ environment ldap.conf ntp/ rc6.d@ stunnel/
audit/ esd.conf ld.so.cache ntp.conf rc.d/ subversion/
autofs_ldap_auth.conf exports ld.so.conf oddjob/ rc.local@ sudoers
auto.master fb.modes ld.so.conf.d/ oddjobd.conf rc.sysinit@ sysconfig/
auto.misc filesystems lftp.conf oddjobd.conf.d/ readahead.d/ sysctl.conf
auto.net* firmware/ libaudit.conf openldap/ reader.conf syslog.conf
auto.smb* fonts/ libuser.conf opt/ reader.conf.d/ tcsd.conf
[root@yubing etc]# ls -F|grep '/$' 找出etc下的目录先用-F在目录后加上/ 然后用grep滤
acpi/
alsa/
alternatives/
audisp/
audit/
avahi/
blkid/
bluetooth/
bonobo-activation/
cipe/
cron.d/
cron.daily/
cron.hourly/
cron.monthly/
cron.weekly/
cups/
dbus-1/
default/
depmod.d/
dev.d/
dnsmasq.d/
.....
[root@yubing etc]# ls -l | grep '^d' 或者是过滤出以d开头的
drwxr-xr-x 4 root root 4096 Apr 7 01:44 acpi
drwxr-xr-x 4 root root 4096 Apr 7 01:43 alsa
drwxr-xr-x 2 root root 4096 Apr 7 01:45 alternatives
drwxr-x--- 3 root root 4096 Apr 7 01:44 audisp
drwxr-x--- 2 root root 4096 Apr 7 01:44 audit
drwxr-xr-x 4 root root 4096 Apr 7 01:45 avahi
drwxr-xr-x 2 root root 4096 Apr 16 22:52 blkid
drwxr-xr-x 2 root root 4096 Apr 7 01:46 bluetooth
drwxr-xr-x 2 root root 4096 Apr 7 01:42 bonobo-activation
drwxr-xr-x 2 root root 4096 Apr 10 18:31 cipe
drwx------ 2 root root 4096 Jan 6 2010 cron.d
drwxr-xr-x 2 root root 4096 Apr 7 01:45 cron.daily
........
[root@yubing etc]# ls -l | grep '^d' | wc -l 计算当前目录下的目录个数
82
[root@yubing etc]# ls -l | grep '^-' |wc -l 计算当前目录下的文件个数
115