Shel l中 ls 使用参数多样化查看文件和目录
列出文件名和目录(ls)
ls [选项] [文件]
[root@test ~]
anaconda-ks.cfg
Desktop
Documents
Downloads
Music
Pictures
Public
Templates
Videos
- 长列表显示文件和目录,包括文件类型、大小、修改日期和时间、权限等信息
[root@test ~]# ls -l
total 12
-rw-------. 1 root root 8619 May 6 2014 anaconda-ks.cfg
drwxr-xr-x. 3 root root 19 May 14 05:20 Desktop
drwxr-xr-x. 2 root root 6 May 8 13:56 Documents
drwxr-xr-x. 2 root root 6 May 8 13:56 Downloads
drwxr-xr-x. 2 root root 6 May 8 13:56 Music
drwxr-xr-x. 2 root root 6 May 8 13:56 Pictures
drwxr-xr-x. 2 root root 6 May 8 13:56 Public
drwxr-xr-x. 2 root root 6 May 8 13:56 Templates
drwxr-xr-x. 2 root root 6 May 8 13:56 Videos
# $1 $2 $3 $4 $5 $6 $7
从上面输出可以看到7个字段,含义分别如下:
(#)第一个字符:文件类型
- :普通文件
d :目录
s :套接字文件
l :链接文件
($1)字段1: 文件权限
($2)字段2: 链接数
($3)字段3: 所有者
($4)字段4: 用户组
($5)字段5: 文件大小
($6)字段6: 文件最近一次被修改的日期时间
($7)字段7: 文件名
[root@test ~]# ls -lh
total 12K
-rw-------. 1 root root 8.5K May 6 2014 anaconda-ks.cfg
drwxr-xr-x. 3 root root 19 May 14 05:20 Desktop
drwxr-xr-x. 2 root root 6 May 8 13:56 Documents
drwxr-xr-x. 2 root root 6 May 8 13:56 Downloads
drwxr-xr-x. 2 root root 6 May 8 13:56 Music
drwxr-xr-x. 2 root root 6 May 8 13:56 Pictures
drwxr-xr-x. 2 root root 6 May 8 13:56 Public
drwxr-xr-x. 2 root root 6 May 8 13:56 Templates
drwxr-xr-x. 2 root root 6 May 8 13:56 Videos
[root@test ~]
123/ date.sh* lib@ test
[root@test ~]
/ : 表示目录
无特殊字符: 表示普通文件
@ : 表示链接文件
* : 表示可执行文件
[root@test ~]
drwxr-xr-x. 2 root root 6 May 14 09:04 /mnt/123/file2
[root@test ~]# ls -R /mnt/
/mnt/:
123 date.sh lib test
/mnt/123:
file1 file2
/mnt/123/file1:
test
/mnt/123/file2:
linux
- 将长列表格式按文件或目录的修改时间 倒序地 列出文件和目录
[root@test ~]# ls -ltr /mnt/
total 4
lrwxrwxrwx. 1 root root 7 May 14 08:58 lib -> usr/lib
-rwxr-xr-x. 1 root root 5 May 14 08:59 date.sh
-rw-r--r--. 1 root root 0 May 14 08:59 test
drwxr-xr-x. 4 root root 30 May 14 09:04 123
[root@test ~]# ls -ls /mnt/
total 4
0 drwxr-xr-x. 4 root root 30 May 14 09:04 123
4 -rwxr-xr-x. 1 root root 5 May 14 08:59 date.sh
0 lrwxrwxrwx. 1 root root 7 May 14 08:58 lib -> usr/lib
0 -rw-r--r--. 1 root root 0 May 14 08:59 test
- 显示包括隐藏文件或目录在内的所有文件和目录,包括 “.“(当前目录),“..“(父目录)
[root@test ~]# ls -a
. .bash_profile Desktop
.. .bashrc Documents
.gnuplot_history Pictures test
- 显示包括隐藏文件或目录在内的所有文件和目录,但不列出 “.” (目前目录) 及 “..” (父目录)
[root@test ~]# ls -A
.bash_profile Desktop
.bashrc Documents
.gnuplot_history Pictures test
- 显示文件或目录的 inode 编号,可能会用在系统维护操作时
[root@test ~]# ls -i /mnt/
27914670 123 11753058 date.sh
11753056 lib 11753057 test
- 显示 uid 和 gid ,代替显示所有者和用户组
[root@test ~]# ls -n
total 16
-rw-------. 1 0 0 8619 May 6 2014 anaconda-ks.cfg
drwxr-xr-x. 3 0 0 19 May 14 05:20 Desktop
drwxr-xr-x. 2 0 0 6 May 8 13:56 Documents
drwxr-xr-x. 2 0 0 6 May 8 13:56 Downloads
drwxr-xr-x. 2 0 0 6 May 8 13:56 Music
drwxr-xr-x. 2 0 0 6 May 8 13:56 Pictures
drwxr-xr-x. 2 0 0 6 May 8 13:56 Public
drwxr-xr-x. 2 0 0 6 May 8 13:56 Templates
-rw-r--r--. 1 0 0 7 May 14 09:16 test
drwxr-xr-x. 2 0 0 6 May 8 13:56 Videos