linux系统中ls命令详解
ls常用参数
·
ls命令的作用:
显示指定工作目录下的文件及属性信息。
语法格式:
ls [参数…] [文件…] ,[]表示可选,即可有可无,…表示可以有多个。
ls:查看当前目录下的文件
[root@localhost /]# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
[root@localhost /]#
ls常用参数:
-l,使用长格式列出文件及目录的详细信息(也就是显示文件的属性信息)。
ll 等价于ls -l
[root@localhost ~]# ls -l
total 21696
-rw-------. 1 root root 1206 Aug 7 19:32 anaconda-ks.cfg
-rw-r--r-- 1 root root 22212558 Aug 20 09:22 farm-ucenter1.5.zip
drwxr-xr-x 6 root root 110 Jun 12 2011 upload
[root@localhost ~]#
-a,显示所有文件及目录(包括以“.”开头的隐藏文件)。
[root@localhost ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc farm-ucenter1.5.zip .pki upload
.. .bash_history .bash_profile .cshrc .mysql_history .tcshrc .viminfo
[root@localhost ~]#
-h,以人性化方式显示目录内容,也就是给文件添加大小单位,通常以ls -lh使用。
对比一下ls -l和ls -lh
[root@localhost ~]# ls -l
total 21696
-rw-------. 1 root root 1206 Aug 7 19:32 anaconda-ks.cfg
-rw-r--r-- 1 root root 22212558 Aug 20 09:22 farm-ucenter1.5.zip
drwxr-xr-x 6 root root 110 Jun 12 2011 upload
[root@localhost ~]# ls -lh
total 22M
-rw-------. 1 root root 1.2K Aug 7 19:32 anaconda-ks.cfg
-rw-r--r-- 1 root root 22M Aug 20 09:22 farm-ucenter1.5.zip
drwxr-xr-x 6 root root 110 Jun 12 2011 upload
[root@localhost ~]#
-R,递归的列出所有的子目录,也就是子目录下的内容也会显示出来。
-d,显示目录本身信息。
-t,根据最后的修改时间排序显示目录内容。
-r,将文件以相反次序显示(默认以英文字母次序)。
[root@localhost ~]# ls -r
upload farm-ucenter1.5.zip anaconda-ks.cfg
[root@localhost ~]#
-s,显示文件大小。
[root@localhost ~]# ls -s
total 21696
4 anaconda-ks.cfg 21692 farm-ucenter1.5.zip 0 upload
[root@localhost ~]#
-S,根据文件大小排序显示目录内容。
[root@localhost ~]# ls -s
total 21696
4 anaconda-ks.cfg 21692 farm-ucenter1.5.zip 0 upload
[root@localhost ~]# ls -S
farm-ucenter1.5.zip anaconda-ks.cfg upload
[root@localhost ~]#
-i,输出文件的inode节点信息。
[root@localhost ~]# ls -i
33574978 anaconda-ks.cfg 33574982 farm-ucenter1.5.zip 50756629 upload
[root@localhost ~]#
ls可以查找多个目录的内容,还可以查找某个文件,可以用通配符星号表示。例如:要查找以a开头的文件,可以使用ls -a*命令。
我们一般常用的:ls , ls -l , ls -a , 其它的参数根据我们的需求来使用,没有要求就不需要用。
看完感觉对你有作用,有帮助,就给小老弟点个赞,加个关注,后续还会发布其它常用的linux知识点。感谢感谢!!!
更多推荐
已为社区贡献1条内容
所有评论(0)