📄 txtdel.sh
字号:
#!/bin/shflag=0if [ $# -eq 0 ]thenfor ii in `ls`do if [ "${ii##*.}" = "txt" ] then flag=$(($flag+1)) fidone#if [ `ls *|wc -l ` -lt `touch 1.txt && ls *|wc -l` ]if [ "$flag" -eq 0 ] then echo "Error! The directory does not contain any files witn a .txt extension" echo elsefor i in ` ls *.txt`do echo File : $i head -n 3 $i|awk '{ print NR ": " $0 }'|sed 's/^/Line /' echo -n "Delete ? Y|N: " read a if [ "$a" = "Y" ] then rm $i echo "File $i has been deleted " elif [ "$a" = "N" ] ; then echo "File $i was NOT deleted " fi echodone fifi while [ $# -gt 0 ]do if [ ! -f `pwd`/$1 ] then echo "Error! File $1 does not exist in the directory " echo elif [ ${1##*.} = "txt" ] then echo "File: $1" head -n 3 $1|awk '{ print NR ": " $0 }'|sed 's/^/Line /' echo -n " Delete ? Y|N " read a if [ "$a" = "Y" ] then rm $1 echo "File $1 has been deleted " elif [ "$a" = "N" ] ; then echo "File $1 was NOT deleted " fi echo else echo "Error! Unable to process $1.I can only deleted files witn .txt extnsion" echo fishiftdone echo "No more .txt file to process. Finished!" echo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -