Unix: Do something if a command fails or is successful

Do something if a command fails:

rm -rf somedir || chmod 777 somedir; rm -rf somedir

Do something if a command is successful:

chmod 777 somedir && rm -rf somedir 

Combine them:

chmod 777 somedir && rm -rf somedir || echo "somedir not found" 

 

Gareth
Buy Me A Coffee
back arrowBack to Index