linux 中ls命令实现对文件的排序
001、ls默认是按照文件名称顺序列出的
[root@PC1 test02]# ls ## 测试文件 a.txt b.txt c.txt [root@PC1 test02]# ls -l ## 默认按照文件名称顺序 total 125000 -rw-r--r--. 1 root root 15360000 Jul 4 19:45 a.txt -rw-r--r--. 1 root root 102400000 Jul 4 19:43 b.txt -rw-r--r--. 1 root root 10240000 Jul 4 19:44 c.txt
002、-r表示反向列出
[root@PC1 test02]# ls ## 测试文件 a.txt b.txt c.txt [root@PC1 test02]# ls -l total 125000 -rw-r--r--. 1 root root 15360000 Jul 4 19:45 a.txt -rw-r--r--. 1 root root 102400000 Jul 4 19:43 b.txt -rw-r--r--. 1 root root 10240000 Jul 4 19:44 c.txt [root@PC1 test02]# ls -lr ## -r表示反向列出 total 125000 -rw-r--r--. 1 root root 10240000 Jul 4 19:44 c.txt -rw-r--r--. 1 root root 102400000 Jul 4 19:43 b.txt -rw-r--r--. 1 root root 15360000 Jul 4 19:45 a.txt
003、ls -S:实现按照文件大小排序
[root@PC1 test02]# ls ## 一共三个测试文件 a.txt b.txt c.txt [root@PC1 test02]# ls -Slh ## -S表示按照大小反向列出,l表示列出,h表示人类可读 total 123M -rw-r--r--. 1 root root 98M Jul 4 19:43 b.txt -rw-r--r--. 1 root root 15M Jul 4 19:45 a.txt -rw-r--r--. 1 root root 9.8M Jul 4 19:44 c.txt
004、-t表示按照创建文件的先后顺序列出,默认最新创建的放在前面
[root@PC1 test02]# ls a.txt b.txt c.txt [root@PC1 test02]# ls -l ## 按照文件名称 total 125000 -rw-r--r--. 1 root root 15360000 Jul 4 19:45 a.txt -rw-r--r--. 1 root root 102400000 Jul 4 19:43 b.txt -rw-r--r--. 1 root root 10240000 Jul 4 19:44 c.txt [root@PC1 test02]# ls -lt ## 按照文件创建的顺序 total 125000 -rw-r--r--. 1 root root 15360000 Jul 4 19:45 a.txt -rw-r--r--. 1 root root 10240000 Jul 4 19:44 c.txt -rw-r--r--. 1 root root 102400000 Jul 4 19:43 b.txt [root@PC1 test02]# ls -ltr ## -r表示逆向输出 total 125000 -rw-r--r--. 1 root root 102400000 Jul 4 19:43 b.txt -rw-r--r--. 1 root root 10240000 Jul 4 19:44 c.txt -rw-r--r--. 1 root root 15360000 Jul 4 19:45 a.txt
。
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2021-07-04 linux系统中文件开头、结尾的空行
2021-07-04 linux系统中unset清楚变量
2021-07-04 linux系统中如何删除行首、行尾的空格
2021-07-04 linux系统中在指定行后添加空行
2021-07-04 linux系统中如何将多个连续的空行合并为一个空行
2021-07-04 linux系统中如何删除空行
2021-07-04 linux系统中grep同时提取以特定字符开头的行、以特定字符结尾的行