txtdel.sh

来自「本shell脚本可以判定当前文件是否有.txt文件」· Shell 代码 · 共 71 行

SH
71
字号
#!/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 + =
减小字号Ctrl + -
显示快捷键?