Linux ls命令最实用的参数是哪个你知道吗?

Linux ls命令最实用的参数是哪个你知道吗?
显示完整的日期
ls --full-time

[root@10-13-53-194 tmp]# ls -l
total 12
-rw-r--r-- 1 root root  178 Jul 18 10:05 a.txt
-rw-r--r-- 1 root root  535 Jul 18 10:30 b.txt
-rw-r--r-- 1 root root 1425 Jul 18 10:00 test.txt
[root@10-13-53-194 tmp]# ls --full-time
total 12
-rw-r--r-- 1 root root  178 2021-07-18 10:05:51.594669159 +0800 a.txt
-rw-r--r-- 1 root root  535 2021-07-18 10:30:43.906128758 +0800 b.txt
-rw-r--r-- 1 root root 1425 2021-07-18 10:00:06.046537330 +0800 test.txt

-a 列出所有的文件

-A 列出除 . 和 … 以外的所有文件

[root@10-13-53-194 tmp]# ls -a
.  ..  a.txt  b.txt  .lesshst  test.txt
[root@10-13-53-194 tmp]#
[root@10-13-53-194 tmp]# ls -A
a.txt  b.txt  .lesshst  test.txt

-B 不列出备份文件,若test.txt 和test.txt~只列出前者

[root@10-13-53-194 tmp]# ls -A
a.txt  a.txt~  b.txt  .lesshst  test.txt
[root@10-13-53-194 tmp]# ls -B
a.txt  b.txt  test.txt

-d 列出目录本身
-d, --directory
list directories themselves, not their contents
去任何一个目录执行这个目录,结果都是下面这样的,不知道这个参数有何用,可能在shell脚本用得着?

[root@10-13-53-194 ~]# ls -d
.

-n 文件所属用户和用户组用uid 和gid表示

-o 不把文件属组列出来

[root@10-13-53-194 tmp]# ls -n
total 16
-rw-r--r-- 1 0 0  178 Jul 18 10:05 a.txt
-rw-r--r-- 1 0 0  178 Aug  4 17:32 a.txt~
-rw-r--r-- 1 0 0  535 Jul 18 10:30 b.txt
-rw-r--r-- 1 0 0 1425 Jul 18 10:00 test.txt
[root@10-13-53-194 tmp]# ls -o
total 16
-rw-r--r-- 1 root  178 Jul 18 10:05 a.txt
-rw-r--r-- 1 root  178 Aug  4 17:32 a.txt~
-rw-r--r-- 1 root  535 Jul 18 10:30 b.txt
-rw-r--r-- 1 root 1425 Jul 18 10:00 test.txt

-Q 用双引号把文件括起来
在这里插入图片描述

-S 文件从大到小列出

[root@10-13-53-194 tmp]# ls -S
test.txt  b.txt  a.txt  a.txt~
[root@10-13-53-194 tmp]#
[root@10-13-53-194 tmp]# ls -S -lh
total 16K
-rw-r--r-- 1 root root 1.4K Jul 18 10:00 test.txt
-rw-r--r-- 1 root root  535 Jul 18 10:30 b.txt
-rw-r--r-- 1 root root  178 Jul 18 10:05 a.txt
-rw-r--r-- 1 root root  178 Aug  4 17:32 a.txt~

-r 按正常顺序的反序列出文件

[root@10-13-53-194 tmp]# ls -l
total 16
-rw-r--r-- 1 root root  178 Jul 18 10:05 a.txt
-rw-r--r-- 1 root root  178 Aug  4 17:32 a.txt~
-rw-r--r-- 1 root root  535 Jul 18 10:30 b.txt
-rw-r--r-- 1 root root 1425 Jul 18 10:00 test.txt
[root@10-13-53-194 tmp]#
[root@10-13-53-194 tmp]# ls -r -l
total 16
-rw-r--r-- 1 root root 1425 Jul 18 10:00 test.txt
-rw-r--r-- 1 root root  535 Jul 18 10:30 b.txt
-rw-r--r-- 1 root root  178 Aug  4 17:32 a.txt~
-rw-r--r-- 1 root root  178 Jul 18 10:05 a.txt

-t 按修改时间的顺序列出文件

[root@10-13-53-194 tmp]# ls -t -l
total 16
-rw-r--r-- 1 root root  178 Aug  4 17:32 a.txt~
-rw-r--r-- 1 root root  535 Jul 18 10:30 b.jpg
-rw-r--r-- 1 root root  178 Jul 18 10:05 a.txt
-rw-r--r-- 1 root root 1425 Jul 18 10:00 test.txt
[root@10-13-53-194 tmp]# ls -t --full-time
total 16
-rw-r--r-- 1 root root  178 2021-08-04 17:32:09.607009619 +0800 a.txt~
-rw-r--r-- 1 root root  535 2021-07-18 10:30:43.906128758 +0800 b.jpg
-rw-r--r-- 1 root root  178 2021-07-18 10:05:51.594669159 +0800 a.txt
-rw-r--r-- 1 root root 1425 2021-07-18 10:00:06.046537330 +0800 test.txt
[root@10-13-53-194 tmp]#

-1(数字1) 每行列出一个文件
这个参数超级实用有木有,每次要把目录下面的文件都列出来,每个文件名一行,输入到一个文件都用ls -l | awk ‘{print $NF}’,还要去掉total,这个ls -1直接把这些复杂的东西给做了

[root@10-13-53-194 tmp]# ls -1
a.txt
a.txt~
b.txt
test.txt

-Z, --context
print any security context of each file
-Z 显示安全的内容????不知道是啥

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值