#!/bin/sh
#删除文件夹下最早的文件
#使用: bash ./del_old_file.sh /d/videos
echo "文件夹路径: $1" #$1 是输入的文件夹路径
#ls -lrt 将文件夹下的文件按修改时间从早到晚排序
#grep '.txt' 是筛选所有txt文件
#head -n 1 是取出排第一的文件,即最早创建的文件
#awk '{print $9}' 取出文件名
oldest_file=$(ls -lrt $1 | grep '.txt'| head -n 1 | awk '{print $9}')
echo "oldest_file : $oldest_file"
file_path=$1"/"$oldest_file
echo "file_path : $file_path"
rm -f $file_path
shell - 删除文件夹下最早的文件
最新推荐文章于 2024-09-04 18:45:20 发布