【命令名称】 ls
【使用权限】 所有人
【命令功能】 列出当前目录上的文件名
【命令语法】 ls [-laFdhSr --full-time等等] 目录名称
【常用参数】
-l 列出长数据段,包括文件的属性与权限,容量等。常用
-a 列出全部的文件,包括隐藏文件,常用
-F 根据文件,目录的信息给予附加数据结构
* 代表可执行文件
/代表目录
=代表SOCKET文件
|代表FIFO文件
@代表链接文件
-d 列出目录本身,而非目录的内容
-h 将文件容量以容易读的方式列出
-S 将已文件容量进行排序,而不已文件名排序
-r 反向输出,将文件名由大到小输出
-t 以时间排序,而不是以文件名
--full-time 列出完整的时时间
【命令实例】
1. 将目录以长数据格式输出
[cxc@cxcserver init.d]$ ls -l /
total 170
drwxr-xr-x 2 root root 4096 Dec 20 10:51 bin
drwxr-xr-x 4 root root 1024 Dec 14 15:56 boot
drwx----wx 2 root root 4096 Jan 2 15:18 data
drwxr-xr-x 11 root root 4200 Jan 11 21:13 dev
drwxr-xr-x 91 root root 12288 Jan 11 21:13 etc
drwxr-xr-x 5 root root 4096 Dec 25 20:52 home
………..中间省略…………..
drwxrwxrwt 8 root root 4096 Jan 11 22:15 tmp
drwxr-xr-x 14 root root 4096 Dec 25 20:59 usr
drwxr-xr-x 24 root root 4096 Dec 14 15:49 var
2. 会在文件的末尾显示出该文件的代表类型
[cxc@cxcserver init.d]$ ls -laF /etc
total 3100
drwxr-xr-x 91 root root 12288 Jan 11 21:13 ./
drwxr-xr-x 24 root root 4096 Jan 11 21:13 ../
drwxr-xr-x 4 root root 4096 Feb 23 2012 acpi/
-rw-r--r-- 1 root root 50 Jan 10 22:03 adjtime
drwxr-xr-x 4 root root 4096 Dec 13 19:07 alchemist/
-rw-r--r-- 1 root root 1512 Apr 26 2005 aliases
………..中间省略…………..
-rw------- 1 root root 3902 Apr 20 2012 autofs_ldap_auth.conf
-rw-r--r-- 1 root root 717 Apr 20 2012 auto.master
-rw-r--r-- 1 root root 581 Apr 20 2012 auto.misc
-rwxr-xr-x 1 root root 1292 Apr 20 2012 auto.net*
-rwxr-xr-x 1 root root 742 Apr 20 2012 auto.smb*
drwxr-xr-x 4 root root 4096 Dec 14 15:55 avahi/
[cxc@cxcserver init.d]$
3. 目录容量显而易见
[cxc@cxcserver init.d]$ ls -lh /
total 170K
drwxr-xr-x 2 root root 4.0K Dec 20 10:51 bin
drwxr-xr-x 4 root root 1.0K Dec 14 15:56 boot
drwx----wx 2 root root 4.0K Jan 2 15:18 data
drwxr-xr-x 11 root root 4.2K Jan 11 21:13 dev
drwxr-xr-x 91 root root 12K Jan 11 21:13 etc
drwxr-xr-x 3 root root 4.0K Jan 7 11:41 root
………..中间省略…………..
drwxr-xr-x 2 root root 12K Dec 25 19:09 sbin
drwxr-xr-x 2 root root 4.0K May 11 2011 selinux
drwxr-xr-x 2 root root 4.0K May 11 2011 srv
drwxr-xr-x 11 root root 0 Jan 12 2013 sys
drwxrwxrwt 8 root root 4.0K Jan 11 22:15 tmp
drwxr-xr-x 14 root root 4.0K Dec 25 20:59 usr
drwxr-xr-x 24 root root 4.0K Dec 14 15:49 var
[cxc@cxcserver init.d]$
4. 只显示/etc下目录
[cxc@cxcserver init.d]$ ls -l /etc |grep ^d
drwxr-xr-x 4 root root 4096 Feb 23 2012 acpi
drwxr-xr-x 4 root root 4096 Dec 13 19:07 alchemist
drwxr-xr-x 4 root root 4096 Dec 13 19:06 alsa
drwxr-xr-x 2 root root 4096 Dec 14 15:58 alternatives
drwxr-x--- 3 root root 4096 Dec 14 15:52 audisp
drwxr-x--- 2 root root 4096 Dec 14 15:52 audit
drwxr-xr-x 4 root root 4096 Dec 14 15:55 avahi
………..中间省略…………..
drwx------ 2 root root 4096 Jan 9 18:19 cron.d
drwxr-xr-x 2 root root 4096 Dec 14 15:55 cron.daily
drwxr-xr-x 2 root root 4096 Dec 13 19:08 cron.hourly
drwxr-xr-x 2 root root 4096 Dec 13 19:06 cron.monthly
drwxr-xr-x 2 root root 4096 Dec 14 15:55 cron.weekly
5.只显示/etc这个目录,不显示etc下面的目录
[cxc@cxcserver init.d]$ ls -ld /etc
drwxr-xr-x 91 root root 12288 Jan 11 21:13 /etc