linux 脚本批量删除,Linux Shell使用Bash脚本批量删除文件

这篇博客介绍了一个用Bash脚本实现的删除工具,该脚本读取由PHP生成的.out文件,该文件包含需要删除的临时文件列表。每个.out文件的每一行对应一个待删除的文件。脚本首先检查文件是否存在和可读,然后逐行处理并删除文件。执行示例展示了脚本成功删除了一系列的临时文件。
摘要由CSDN通过智能技术生成

PHP每天生成一个存有系统要删除的临时文件的.out文件列表,由bash脚本逐行通过读取.out文件(每一行代表一个待删除的文件)挨个删除,代码如下(dl.sh): #!/bin/bash # Shell script utility to delete file. # You can call script as follows, to read m

PHP每天生成一个存有系统要删除的临时文件的.out文件列表,由bash脚本逐行通过读取.out文件(每一行代表一个待删除的文件)挨个删除,代码如下(dl.sh):

#!/bin/bash

# Shell script utility to delete file.

# You can call script as follows, to read myfile.txt:

# ./dl.sh or.txt

# Copyright (c) 2009 kokko <>

#User define Fuction(UDF)

processLine(){

line="$@" #get all args

if [ ! -f $FILE ]; then

echo "$line does not exists"

else

echo "$line"

rm -rf $line

fi

}

#echo Please enter the file name:

#read FILE

if [ ! "$1" == "" ]; then

FILE="$1"

else

echo Please enter the file name:

read FILE

fi

if [ ! -f $FILE ]; then

echo "$FILE does not exists"

exit 1

elif [ ! -r $FILE ]; then

echo "$FILE cann't read"

fi

#read $FILE using the file descriptors

BAKIFS=$IFS

IFS=$(echo -en "\n\b")

exec 3

exec 0

while read -r line

do

processLine $line

done

exec 0

IFS=$BAKIFS

exit 0

执行:

kokkowon@itbeing.com [~/www]# ./dl.sh ./temp.out

结果:

./message.tmp

./ECShop_V2.7.1_UTF8_Release1228.zip

./captcha.tmp

./index.tmp

./goods_script.tmp

./region.tmp

./article.tmp

./comment.tmp

./animated_favicon.gif

./auction.tmp

./catalog.tmp

./category.tmp

./affiche.tmp

./group_buy.tmp

./search.tmp

./favicon.ico

./itbeing/Cache/776e414da1b246fca4e72f34d6e5cce9.tmp

./itbeing/Cache/e8a01c49e3bd6881d1526bce80cbcad7.tmp

./itbeing/Cache/13da2f5482df2335081ce60c3ac5828c.tmp

./itbeing/Cache/aec1e7b1c552ce75969652a157572320.tmp

./pm.tmp

./respond.tmp

./exchange.tmp

./flow.tmp

./myship.tmp

./sitemaps.tmp

./snatch.tmp

./error_log

./article_cat.tmp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值