命令名称
ls - 列出目录内容
ls命令语法
ls [OPTION]... [FILE]...
ls命令描述
列出文件信息(默认是当前目录),以字母顺序排序(如果使用没有任何 -cftuvSUX 或 --sort选项)
ls命令常用选项
作为linux下最常用的命令,ls的常用选项也很多。
选项 | 描述 |
-a, --all | 列出所有的项,包括以.开头的文件或目录。 |
-A, --almost-all | 列出除了.和..以外的所有项 |
--author | 和-l选项一起使用,列出文件的作者 |
-c | 和-lt选项一起使用,按ctime(最后更改文件状态信息时间)排序 |
-d, --directory | 只列出目录 |
-l | 按详情格式显示,各字段意思请看实例。 |
-r, --reverse | 排序的时候使用倒序 |
-R, --recursive | 列出子目录 |
-S | 按文件大小排序 |
-t | 按修改时间(mtime)排序 |
-u | 与-lt选项一起使用,按访问时间(atime)排序 |
-U | 不做任何排序 |
-1 | 字母1,一行只列出一个文件 |
ls命令实例
下面实例演示ls的各种常见用法。
[root@shellcn.net test#] ls
1.txt 5.txt a.log mysql.sh
######列出详情,七个列依次是
######权限,硬链接数或目录的子目录数,所有者,所属用户组,文件大小byte,mtime(修改时间,最后一次写文件内容时间),文件名
[root@shellcn.net test#] ls -l
total 8
-rw-r--r--. 1 root root 0 Oct 7 05:54 1.txt
-rw-r--r--. 1 root root 843 Apr 18 19:55 5.txt
-rw-r--r--. 1 root root 0 Oct 7 05:55 a.log
-rwxr--r--. 1 root root 10 Apr 16 19:26 mysql.sh
######显示所有文件,包括..和.
[root@shellcn.net test#] ls -al
total 16
drwxr-xr-x. 2 root root 4096 Oct 7 05:56 .
dr-xr-x---. 3 root root 4096 Oct 7 05:56 ..
-rw-r--r--. 1 root root 0 Oct 7 05:54 1.txt
-rw-r--r--. 1 root root 843 Apr 18 19:55 5.txt
-rw-r--r--. 1 root root 0 Oct 7 05:55 a.log
-rwxr--r--. 1 root root 10 Apr 16 19:26 mysql.sh
######按大小排序
[root@shellcn.net test#] ls -Sl
total 8
-rw-r--r--. 1 root root 843 Apr 18 19:55 5.txt
-rwxr--r--. 1 root root 10 Apr 16 19:26 mysql.sh
-rw-r--r--. 1 root root 0 Oct 7 05:54 1.txt
-rw-r--r--. 1 root root 0 Oct 7 05:55 a.log
######按mtime排序
[root@shellcn.net test#] ls -tl
total 8
-rw-r--r--. 1 root root 0 Oct 7 05:55 a.log
-rw-r--r--. 1 root root 0 Oct 7 05:54 1.txt
-rw-r--r--. 1 root root 843 Apr 18 19:55 5.txt
-rwxr--r--. 1 root root 10 Apr 16 19:26 mysql.sh
######按ctime排序
[root@shellcn.net test#] ls -lct
total 8
-rwxr--r--. 1 root root 10 Oct 7 05:56 mysql.sh
-rw-r--r--. 1 root root 843 Oct 7 05:55 5.txt
-rw-r--r--. 1 root root 0 Oct 7 05:55 a.log
-rw-r--r--. 1 root root 0 Oct 7 05:54 1.txt
######按atime排序
[root@shellcn.net test#] ls -ltu
total 8
-rw-r--r--. 1 root root 0 Oct 7 05:55 a.log
-rw-r--r--. 1 root root 0 Oct 7 05:54 1.txt
-rwxr--r--. 1 root root 10 Apr 18 22:55 mysql.sh
-rw-r--r--. 1 root root 843 Apr 18 19:56 5.txt