Sign in to follow this  
Followers 0

Useful script

1 post in this topic

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.

### - 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
elif [ $decision = "y" ]; then
for line in $(cat filesToDelete.list)
do rm -f $line
elif [ $decision = "n" ]; then
else cleanup


Edited by frogbong

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0