???????????Linux?е????
???????????? ???????[ 2014/11/10 10:40:38 ] ????????Linux ?????? ?????
??????????? Windows ??????????????? Bash ????? Linux ?????????????? delete ??????? rm ??????????????????????????y??????????1????????? 2G ????????????????????????$HOME/trash ???£???? trash ???е??????????????£????????? trash ???г???????????????
????????
?????????Σ??????????????????????????????????????????? Linux ????????Σ????????????????????rm –rf /* ??????????????????? Linux ????????????????????????????С? ?? Windows ?У????????????????????????????????????????????????????????????????????????????????С??????????????????????????????????????????????е??????????????λ?á??? Linux ?????????????????????? rm ????????У???????????????????????????
?????????????
?????????????????????????????????????Delete ?????logTrashDir ????? restoreTrash ????????? Delete ???????????????????????·?? rm ???????? rm ????????????????????????????????$home/trash ????????????????????????????????? -f ???delete ??????????? rm –f ???????????????????logTrashDir ?????????????????????????? trash ???μ????????????С?restoreTrash ????????????? trash ?е?????????????????·??????? Linux ???У?????????????????/bin/???£????? chmod +X filename ?????????????????????á????潫???????????????????
????Delete ???
??????????
????????????????????????????????????????????$HOME ????? trash ??????????????????????£?
?????嵥 1.???????????
????realrm="/bin/rm"
????if [ ! -d ~/trash ]
????then
????mkdir -v ~/trash
????chmod 777 ~/trash
????fi
????????????????ж???????????????δ????????????????иy???????? trash ???????? realrm ????? Linux ?? rm ???λ?????????????????μ????????????????????
??????????????
?????y???????????????????δ???????????????????????????????????£?
?????嵥 2.??????????
????if [ $# -eq 0 ]
????then
????echo "Usage:delete file1 [file2 file3....]"
????echo "If the options contain -f??then the script will exec 'rm' directly"
???????????????y???????????? delete ??????????????????·?????м?????????
?????????????
??????Щ???????Ч?????????????????????????????У??????????????????Delete ???????-f ?????????????????
?????嵥 3.?????????
while getopts "dfiPRrvW" opt
do
case $opt in
f)
exec $realrm "$@"
;;
*)
# do nothing
;;
esac
done
?????????????????м?????-f ????? delete ??????????? rm ??????????????????????????????????е???????????????? rm ?????????????а??????-f ??????? rm ??????????? rm ?????й?????磺delete –rfv filename ???? rm –rfv filename??
???????????
??????????????????????????????????? Windows ???????????????????????
?????嵥 4.???????
????echo -ne "Are you sure you want to move the files to the trash?[Y/N]:a"
????read reply
????if [ $reply = "y" -o $reply = "Y" ]
????then #####
?????ж??????????????????? 2G ???
????????????????????????????????????????????????????????????????????ж??????????????????????????ж???????С????? 2G??????????????????????????????????????????
?????嵥 5.??????? 2G ?????
for file in $@
do
if [ -f "$file" –o –d "$file" ]
then
if [ -f "$file" ] && [ `ls –l $file|awk '{print $5}'` -gt 2147483648 ]
then
echo "$file size is larger than 2G??will be deleted directly"
`rm –rf $file`
elif [ -d "$file" ] && [ `du –sb $file|awk '{print $1}'` -gt 2147483648 ]
then
echo "The directory:$file is larger than 2G??will be deleted directly"
`rm –rf $file`
???????????????????y???ò???????????ж???????????С???????????С???????????е????????????????С????????????’du -sb’????????????????? awk ?????????????ε??????????
????????????????????????
?????ò????? Delete ??????????????????????????????
???????????????????????????????????п??????·????????????л??????????????????? mv ????????????y??????????????????????’${file##*/}’???????
??????????????????????????м???????????????????μ?????????????????????????????????????????????????????????
???????????????·??????????????????????е???????????????·??????·??????????????????????????????????????????????????·???????????????·?????·?????????????????????????????????ж?????????????????
???????? logTrashDir ?????????????е????????????????????????????·????????????????
???????????? mv ????????? Trash ?????????????????????
?????嵥 6.????????????????????
now=`date +%Y%m%d_%H_%M_%S`
filename="${file##*/}"
newfilename="${file##*/}_${now}"
mark1="."
mark2="/"
if [ "$file" = ${file/$mark2} ]
then
fullpath="$(pwd)/$file"
elif [ "$file" != ${file/$mark1} ]
then
fullpath="$(pwd)${file/$mark1}"
else
fullpath="$file"
fi
echo "the full path of this file is :$fullpath"
if mv -f $file ~/trash/$newfilename
then
$(/logTrashDir "$newfilename $filename $now $fullpath")
echo "files: $file is deleted"
else
echo "the operation is failed"
fi
????logTrashDir ???
?????y?????????????????????д????????????????????????????????????????????????????£?
?????嵥 7.logTrashDir ????
????if [ ! -f ~/trash/.log ]
????then
????touch ~/trash/.log
????chmod 700~/trash/.log
????fi
????echo $1 $2 $3 $4>> ~/trash/.log
?????y???????.log ???????????????????????????????
????restoreTrash ???
?????y???????????1????
??????.log ???????????????????????????????????????? awk????????????????????????????????????
??????????????????????????Σ??????????
????????????е??????????????λ??????????????? mv –b ????????????????-b ???????????λ?????????????????
??????.log ????????????????????????
?????嵥 8.?????????
????originalPath=$(awk /$filename/'{print $4}' "$HOME/trash/.log")
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11