ls 是最常被使用到的 Linux 命令之一,默认不加参数的情况下,ls 会列出当前工作目录的中的文件信息
目录
一、语法格式
ls [参数] [文件]
二、常用参数
-a | 显示所有文件及目录 (包括以“.”开头的隐藏文件) |
-l | 使用长格式列出文件及目录的详细信息 |
-i | 输出 inode 节点信息 |
-t | 根据最后的修改时间排序 |
-d | 查看目录的信息,而不是里面子文件的信息 |
三、命令实战
3.1 输出当前目录中的文件(默认不显示隐藏文件)
[root@linux ~]# ls
cdc deployment.yml docker music mysql nginx
3.2 输出当前目录中的文件(含隐藏文件)
[root@linux ~]# ls -a
. .bash_history .bash_profile .cache .cshrc docker mysql .pki .tcshrc
.. .bash_logout .bashrc cdc deployment.yml music nginx .python_history .viminfo
3.3 输出文件长格式,包含属性详情信息
[root@linux ~]# ls -l
总用量 0
drwxr-xr-x. 2 root root 6 3月 20 13:51 cdc
-rw-r--r--. 1 root root 0 3月 20 13:52 deployment.yml
drwxr-xr-x. 2 root root 6 3月 20 13:51 docker
drwxr-xr-x. 2 root root 6 3月 20 13:46 music
drwxr-xr-x. 2 root root 6 3月 20 13:52 mysql
drwxr-xr-x. 2 root root 24 3月 20 13:53 nginx
3.4 输出文件名称及 inode 块属性块号码
[root@linux ~]# ls -i
60518 cdc 33574998 deployment.yml 16783196 docker 50572169 music 33587443 mysql 50572181 nginx
3.5 输出指定目录中的文件
[root@linux ~]# ls nginx/
nginx.conf
3.6 输出当前目录下的文件,以最后修改时间排序
[root@linux1 ~]# ls -lt
总用量 76
-rw-r--r--. 1 root root 10240 3月 30 11:38 a.tar
-rw-r--r--. 1 root root 27 3月 29 14:25 1.txt
-rw-r--r--. 1 root root 9064 3月 29 14:18 2.txt
-rw-r--r--. 1 root root 9064 3月 29 14:17 filename.txt
......以下省略......
[root@linux1 ~]# ls -l
总用量 76
-rw-r--r--. 1 root root 27 3月 29 14:25 1.txt
-rw-r--r--. 1 root root 9064 3月 29 14:18 2.txt
-rwsrwxr-x. 1 root root 12288 3月 28 10:40 aliases.txt
-rw-r--r--. 1 root root 10240 3月 30 11:38 a.tar
......以下省略......
3.7 输出某个目录信息,只显示目录信息,不显示子文件信息
[root@linux1 ~]# ls -ld date
dr-xr-xr-x. 2 root root 43 3月 28 11:13 date
[root@linux1 ~]# ls -l date
总用量 16
-rw-rw-rw-. 1 root root 12288 3月 28 10:40 aliases.txt
-rw-rw-rw-. 1 root root 1108 3月 28 11:01 chrony.txt