Bash tip: Selective Deletion

terminal.png

If you have a directory that contains ten subdirectories and you want to delete three of them, the slow way to do it would be like this:

rm -rf /home/tuxtraining/work
rm -rf /home/tuxtraining/projects
rm -rf /home/tuxtraining/sandbox

But that’s pretty darn slow and open to making mistakes – a much smarter way to is to let Bash perform multiple filename expansion by placing the options inside braces. For example, this would achieve the same as the three lines from above:

rm -rf /home/tuxtraining/{work,projects,sandbox}

Related Posts

Comments are closed.