linux ls命令 – 显示指定工作目录下的文件及属性信息
ls是最常被使用到的Linux命令之一,来自于英文单词list的缩写,也正如list单词的英文意思,其功能是列举出指定目录下的文件名称及其属性。
默认不加参数的情况下,ls命令会列出当前工作目录中的文件信息,经常与cd和pwd命令搭配使用,十分方便。而带上参数后,我们则可以做更多的事情,作为最基础、最频繁使用的命令,有必要仔细了解下其常用功能。
语法格式: ls [参数] [文件]
常用参数:
-a 显示所有文件及目录 (包括以“.”开头的隐藏文件)
-l 使用长格式列出文件及目录的详细信息
-r 将文件以相反次序显示(默认依英文字母次序)
-t 根据最后的修改时间排序
-A 同 -a ,但不列出 “.” (当前目录) 及 “..” (父目录)
-S 根据文件大小排序
-R 递归列出所有子目录
-d 查看目录的信息,而不是里面子文件的信息
-i 输出文件的inode节点信息
-m 水平列出文件,以逗号间隔
-X 按文件扩展名排序
--color 输出信息中带有着色效果
参考实例
输出当前目录中的文件(默认不含隐藏文件):
[root@linuxcool ~]# ls
anaconda-ks.cfg Documents initial-setup-ks.cfg Pictures Templates
Desktop Downloads Music Public Videos
输出当前目录中的文件(含隐藏文件):
[root@linuxcool ~]# ls -a
. .bashrc Documents Music Videos
.. .cache Downloads Pictures .viminfo
anaconda-ks.cfg .config .esd_auth .pki
.bash_history .cshrc .ICEauthority Public
.bash_logout .dbus initial-setup-ks.cfg .tcshrc
.bash_profile Desktop .local Templates
输出文件的长格式,包含属性详情信息:
[root@linuxcool ~]# ls -l
total 8
-rw-------. 1 root root 1430 Dec 14 08:05 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Dec 14 08:37 Desktop
drwxr-xr-x. 2 root root 6 Dec 14 08:37 Documents
drwxr-xr-x. 2 root root 6 Dec 14 08:37 Downloads
-rw-r--r--. 1 root root 1585 Dec 14 08:34 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 6 Dec 14 08:37 Music
drwxr-xr-x. 2 root root 6 Dec 14 08:37 Pictures
drwxr-xr-x. 2 root root 6 Dec 14 08:37 Public
drwxr-xr-x. 2 root root 6 Dec 14 08:37 Templates
drwxr-xr-x. 2 root root 6 Dec 14 08:37 Videos
输出指定目录中的文件列表:
[root@linuxcool ~]# ls /etc
adjtime hosts pulse
aliases hosts.allow qemu-ga
alsa hosts.deny qemu-kvm
alternatives hp radvd.conf
anacrontab idmapd.conf ras
asound.conf init.d rc0.d
at.deny inittab rc1.d
………………省略部分输出信息………………
输出文件名称及inode属性块号码:
[root@linuxcool ~]# ls -i
35290115 anaconda-ks.cfg 35290137 initial-setup-ks.cfg 35290164 Templates
1137391 Desktop 17840039 Music 51609597 Videos
1137392 Documents 35290165 Pictures
17840038 Downloads 51609596 Public
搭配通配符一起使用,输出指定目录中所有以sd开头的文件名称:
1
2
[root@linuxcool ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2
依据文件大小进行排序,输出指定目录中文件属性详情信息:
[root@linuxcool ~]# ls -Sl /etc
total 1348
-rw-r--r--. 1 root root 692241 Sep 10 2018 services
-rw-r--r--. 1 root root 66482 Dec 14 08:34 ld.so.cache
-rw-r--r--. 1 root root 60352 May 11 2017 mime.types
-rw-r--r--. 1 root dnsmasq 26843 Aug 12 2018 dnsmasq.conf
-rw-r--r--. 1 root root 25696 Dec 12 2018 brltty.conf
-rw-r--r--. 1 root root 9450 Aug 12 2018 nanorc
-rw-r--r--. 1 root root 7265 Dec 14 08:03 kdump.conf
-rw-------. 1 tss tss 7046 Aug 13 2018 tcsd.conf
………………省略部分输出信息………………
- C语言求最大公约数
- 如果有一个自然数a能被自然数b整除,则称a为b的倍数,b为a的约数。几个自然数公有的约数,叫做这几个自然数的公约数。
- 03-12 关注:0
- C语言求勾股数
- 所谓勾股数,是指能够构成直角三角形三条边的三个正整数(a,b,c)。
- 03-11 关注:3
- C语言求回文数
- 将数组中元素重新组合成一新数。拆分时变量a的最高位仍然存储在数组中下标最大的位置
- 03-11 关注:3
- C语言水仙花数
- 输出所有的“水仙花数”,所谓的“水仙花数”是指一个三位数其各位数字的立方和等于该数本身,例如153是“水仙花数”,因为:153 = 13
- 03-11 关注:3
- C语言求自守数
- 自守数是指一个数的平方的尾数等于该数自身的自然数。
- 03-11 关注:2