加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

移除指定目录的文件

发布时间:2020-12-15 16:25:38 所属栏目:安全 来源:网络整理
导读:#!/bin/bash dir1=/root/was1 dir2=/root/was2 #dir1=/wasprofiles/c01-`hostname`/installedApps/cell01 #dir2=/wasprofiles/c02-`hostname`/installedApps/cell02 function del_files { i=1 echo "------------------------------------------------------

#!/bin/bash

dir1=/root/was1

dir2=/root/was2

#dir1=/wasprofiles/c01-`hostname`/installedApps/cell01

#dir2=/wasprofiles/c02-`hostname`/installedApps/cell02


function del_files

{

i=1

echo "----------------------------------------------------------------------"


arr=($1)

for s in ${arr[@]}

do

echo "$i $s"

i=$[$i + 1]

done

echo "----------------------------------------------------------------------"

echo "Choose files to remove.(Example:1 2 3 or all)"

read rmfiles

while test -z "$rmfiles"

echo "Input is null! Please input again.(Example:1 2 3 or all)"

read rmfiles

if [ "$rmfiles" = "all" ] ; then

for rf in ${arr[@]}

do

[ ! -d /tmp/$2 ] && mkdir /tmp/$2

rmname=`sed 's////' <<< "$rf" | sed 's///#/g'`

mv $rf /tmp/$2/$rmname

done

else

for rf in $rmfiles

if grep '^[[:digit:]]*$' <<< "$rf" >/dev/null ; then

arf=$[$rf - 1]

if test -z ${arr[$arf]} ; then

echo "Eeror: Input $rf not exist"

else

[ ! -d /tmp/$2 ] && mkdir /tmp/$2

rmname=`sed 's////' <<< "${arr[$arf]}" | sed 's///#/g'`

mv ${arr[$arf]} /tmp/$2/$rmname

fi

else

echo "Eerror: Input $rf is not number."

fi

done

fi

echo "ls /tmp/$2"

ls -l /tmp/$2

}


echo "Please input was1,was2 or exit."

read line

while test -z "$line" || ([ "$line" != "was1" ] && [ "$line" != "was2" ] && [ "$line" != "exit" ])

do

echo "Input error! Please input was1,'Microsoft YaHei';"> read line

done

echo "----------------------------------------------------------------------"


if [ $line = "was1" ] ; then

echo "Files will be found in $dir1"

echo "Please input filename.(Example: abc 123.txt)"

read filename

while test -z "$filename"

echo "Input is null! Please input again.(Example: abc 123.txt)"

read filename

done


for file in $filename

ffile=`find $dir1 -type f -name $file*`

if test -z "$ffile" ; then

echo "Info: $file is not found."

else

ffiles="$ffile $ffiles"

fi

if test -z "$ffiles" ; then

echo "Can't find input files."

del_files "$ffiles" was1

elif [ $line = "was2" ] ; then

echo "Files will be found in $dir2"

ffile=`find $dir2 -type f -name $file*`

echo "Info: All input files not found!"

del_files "$ffiles" was2

elif [ $line = "exit" ] ; then

exit

fi

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读