Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to prevent exit 1 when blanket rm -R with empty directories

So I am deploying a script to remove several directories of a program we no longer use. It was such a cluster though that not all directories are present on the computers. I am doing a simple rm -R with all the directories listed.

However my script fails when it comes up with "No such file or directory". Is there any way to have the script exit 0 instead of one?
I would like to avoid an if then for simplicity. I’m hoping there is a flag or other operator I don’t know about.

remove several directories and exit 0 even if the directories don’t exist

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the --force/-f flag for this:

$ rm -rf doesnotexist; echo $?
0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading