zoukankan      html  css  js  c++  java
  • Linux之find命令用于统计信息

    1. 计算当前目录中的文件数:

    [root@localhost tmp]# find . -type f | wc -l
    29

    2. 查找/etc目录中最新的和最旧的文件,以文件时间排序并按年-月-日的格式显示:

    #查找最旧的文件
    [root@localhost tmp]# find /etc/ -type f -printf "%T+ %p
    " | 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+ 	%p
    " | 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+ 	%p
    " | 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 	 %f
    " | sort -n | uniq | tail -n 1
    12288    .crontab.vf6XP3.swp

    5. 统计文件的所有者,使用%u参数,并且统计属于同一个所有者的文件数目(可通过uniq -c实现):

    [root@localhost tmp]# find . -type f -printf "%u
    " | grep -v "./." | sort | uniq -c
         29 root
          1 ws

    6. 查看文件的访问日期,使用%a参数:

    [root@localhost tmp]# find . -type f -printf "%a+%p
    " | 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
  • 相关阅读:
    lxml webdriver 抓取街拍
    python 正则抓取古诗词
    2021 最新版 Spring Boot 速记教程
    hbase 命令查看表大小
    Spring AOP,应该不会有比这更详细的介绍了!
    SpringBoot实战:整合Redis、mybatis,封装RedisUtils工具类等
    API接口的安全设计验证:ticket,签名,时间戳
    5.控制台输出空心菱形
    4.灯泡开关问题
    EXCEL函数
  • 原文地址:https://www.cnblogs.com/mengrennwpu/p/4715216.html
Copyright © 2011-2022 走看看