As you might know by now, I like Bash!
So far, we have built some fun stuff using Bash like hacking our morning routine and making an after work git check.
I use Carbon to generate these cool previews for many of my articles. Very cool app, but my Downloads folder gets full of these things.
So how can Bash help us CleanOurMacs?
Bash clean files
Note: This script can be very dangerous since it uses Bash to remove files. Please be cautious!
We will use a txt
file to loop over files we want to remove.
These files can include a wildcard (*) or start with a specific string:
- Start with:
carbon
- Wildcard:
carbon*.png
Then on to the script!
while read line; do
find . -name "$line" -exec rm -rf {} \;
done < ~/www/cleanMyPc/files.txt
echo 'All done';
Wow, simple as that, right?
We loop through the lines in our files.txt
, and for each line, we execute the find
command. It searches for a specific name and calls -exec rm -rf
The rm
stands for remove
and rf
for recursive force
.
Running the script
This script initially worked so it would scan all your files, but I adjusted it for security reasons to only scan a specific folder.
- So open a Terminal
- Navigate to the folder you want:
cd Downloads
- Execute command
~/path/to/script/bash.sh
- Voila, all done
Itโs a straightforward script, but it can be helpful to find/remove specific files on your computer.
Find this project on GitHub
Thank you for reading, and letโs connect!
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter