Shell 脚本1 -- 查看今天更新/创建的文件

#!/bin/bash
# This is a Shell script to find the files created by Today
#
# Usage is:
#
#    test.sh <dir>
#

function recurce()
{
    cd $1             #进入该目录
    for file in * ;         #对目录中的每一个文件都逐一检查
    do
        if [ -d "$file" ]; then        #如果该文件还是目录
            recurce $file
        fi
        
        if [ -f "$file" ] ; then     #如果文件是普通文件
            longfile=`ls -l --time-style=long-iso $file`        #获取文件的信息
            check=`echo $longfile | grep $today`        
            if [ -n "$check" ] ;    then         #查看该文件的信息中的时间是不是今天
                echo "$PWD/$file"
            fi
        fi        
    done
}

function main ()        #主函数,
{
    today=`date +%Y-%m-%d`        #获得当前的时间。
    directory=$1
    if [ -z "$directory" ];then        #如果传入main函数的参数是一个空目录,则输入默认的目录
        directory="."
    fi
    recurce $directory
}

main $1            #脚本入口

exit



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值