Sign in to follow this  
Followers 0
frogbong

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.


#!/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
0

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