linux系统中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知识点。感谢感谢!!!

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值