Linux之find命令用于统计信息
1. 计算当前目录中的文件数:
[root@localhost tmp]# find . -type f | wc -l 29
2. 查找/etc目录中最新的和最旧的文件,以文件时间排序并按年-月-日的格式显示:
#查找最旧的文件 [root@localhost tmp]# find /etc/ -type f -printf "%T+ %p\n" | sort -n | head -n 1 2013-02-22+19:23:47.0000000000 /etc/lsb-release.d/graphics-4.0-ia32 #查找最新的文件 [root@localhost tmp]# find . -type f -printf "%T+ \t%p\n" | sort -n | tail -n 1 2015-08-06+19:57:14.4790036700 ./student.txt
注:printf命令输出中,%T表示文件的日期和时间,%p表示带路径的文件名
3. 查看家目录中不以"."开头的最新的文件:
[root@localhost tmp]# find /home/ -type f -printf "%T+ \t%p\n" | grep -v "ws/\."| sort -n | tail -n 1 2015-08-09+22:39:22.4699979720 /home/file
4. 查找目录中的最大文件,%s参数表示文件大小,%f参数表示包含文件名
[root@localhost tmp]# find . -type f -printf "%s \t %f\n" | sort -n | uniq | tail -n 1 12288 .crontab.vf6XP3.swp
5. 统计文件的所有者,使用%u参数,并且统计属于同一个所有者的文件数目(可通过uniq -c实现):
[root@localhost tmp]# find . -type f -printf "%u\n" | grep -v "\./\." | sort | uniq -c 29 root 1 ws
6. 查看文件的访问日期,使用%a参数:
[root@localhost tmp]# find . -type f -printf "%a+%p\n" | sort Fri Jul 24 00:30:36.0720998929 2015+./sh/variable.sh Mon Aug 3 23:36:49.0879000520 2015+./.viminfo Mon Jul 27 23:11:37.0189000083 2015+./sh/if1.sh Mon Jul 27 23:26:30.0823998314 2015+./sh/readtest.sh Mon Jul 27 23:26:52.0296995712 2015+./sh/readtest,sh Mon Jul 27 23:34:46.0718997111 2015+./sh/if2.sh
7. 运行命令前,临时清空环境变量,可以使用env -i 命令,表示修改环境变量(忽略环境变量),开始一个shell,新shell中没有多余的环境变量
[root@localhost sh]# env | wc -l 28 [root@localhost sh]# env -i env | wc -l 0
分类:
Linux操作基础
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了