Advertisement
ibanezzaro

quota bash non clean

Dec 23rd, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #!/bin/bash
  2. TARGET_DIR=("$@")
  3. [ "x$1" == "x" ] && TARGET_DIR=(".")
  4. function confirmDeletion() {
  5. local confirm=""
  6. until [ "x$confirm" == 'xy' ] || [ "x$confirm" == 'xn' ]
  7. do
  8. read -ep " Delete [y/n]: " confirm
  9. confirm=$(echo "$confirm" | tr [:upper:] [:lower:])
  10. done
  11. [ "x$confirm" == 'xy' ]
  12. }
  13. function deleteWithConfirmation() {
  14. for file in "${@}"
  15. do
  16. if rm "$file"; then
  17. echo " OK: $file"
  18. else
  19. echo " FAIL: $file"
  20. fi
  21. done
  22. }
  23. for i in {'*~','a.out','*.o','*.gch','*nppdf32Log*'}
  24. do
  25. echo "Files matching: $i"
  26. FILES=()
  27. while read -rd '' file
  28. do
  29. FILES+=("$file")
  30. echo " $file"
  31. done < <(find "${TARGET_DIR[@]}" -depth -iname "$i" -print0)
  32. if [ "x${FILES[*]}" != "x" ]; then
  33. if confirmDeletion; then
  34. deleteWithConfirmation "${FILES[@]}"
  35. else
  36. echo " Skipping"
  37. fi
  38. fi
  39. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement