Advertisement
mbazs

Find files/folders and delete them

Jul 13th, 2018
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.78 KB | None | 0 0
  1. if [ -z "$1" ]; then
  2.         echo "Usage: $0 <filename-fraction>"
  3.         exit 1
  4. fi
  5.  
  6. FILES=$(find -maxdepth 1 -name "*$1*" -print0)
  7. echo $FILES
  8.  
  9. read -p "Delete these files / directories? [no]: " ANS
  10. if [[ "$ANS" =~ [yY][eE][sS] ]]; then
  11.         while IFS= read -r -d '' f; do
  12.                 ### rm -rf $f
  13.                 echo $f
  14.         done <<< "$FILES"
  15. fi
  16.  
  17. ==============
  18. Működő verzió:
  19. ==============
  20.  
  21. if [ -z "$1" ]; then
  22.         echo "Usage: $0 <filename-fraction>"
  23.         exit 1
  24. fi
  25.  
  26. IFS=$'\0'
  27. FILES=$(find -maxdepth 1 -name "*$1*")
  28. [[ -z "$FILES" ]] && exit 0
  29. echo "$FILES"
  30.  
  31. read -p "Delete these files / directories? [no]: " ANS
  32. if [[ "$ANS" =~ [yY][eE][sS] ]]; then
  33.         while read -r f; do
  34.                 rm -rf $f
  35.         done <<< "$FILES"
  36. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement