Jump to content


Photo
- - - - -

Useful script


  • Please log in to reply
No replies to this topic

#1 frogbong

frogbong

    mad 1337

  • Members
  • 134 posts
  • Country:
  • Gender:Male

Posted 26 April 2010 - 01:08 AM

Have you ever had multiple(and similarly named) files on your file-system that you wanted to delete but they were scattered in different directories across the system? This can help delete all of those files without having to rm -f them one by one.

#!/bin/sh
##
### delfiles.sh - delete a group of similarly named files no matter where they are on the system
##
#
findfiles() {
  sudo echo "Enter extension to look for: "
  read extension
  echo "Results:"
  echo "--------"
  sudo find /* -name *$extension*
  echo "--------"
  echo "End of Results." 
  echo "Saving results to a file.."
  sudo find /* -name *$extension* > filesToDelete.list
  echo "Done."
}

cleanup() {
  rm -f filesToDelete.list
  echo "Aborted. Cleaning up.."
  echo "Exiting.."
}

deletefiles() {
  echo "Delete listed files(y or n)?"
  read decision
  if [ -z $decision ]; then
    cleanup
  elif [ $decision = "y" ]; then
    for line in $(cat filesToDelete.list)
      do rm -f $line
    done
  elif [ $decision = "n" ]; then
    cleanup    
  fi 
  else cleanup 
}

findfiles
deletefiles

Edited by frogbong, 17 June 2010 - 07:29 PM.





BinRev is hosted by the great people at Lunarpages!