Joined November 2012
·

Daniel Pecos Martínez

CapGemini
·
Valencia (Spain)
·
·
·

@lokiastari I needed this command while creating a deployment script for a webapp to a pristine directory structure, so rsync was not a suitable solution.

That's why I needed to empty a directory path completely before making the deployment.

I find it's quite usefull and fits great in the script, and also great used as an alias in the command line.

@lokiastari Well, I don't quite understand what you're saying about maintaining an script and being fired or not (are scripts written once and remain intact forever without a minimal maintenance?? lol ). I'm not going to enter into that discussion but try to focus on the actual subject.

Anyway, your latest version works fine, but you are not handling exit codes properly. In fact, you don't seem to care about if the rm could or could not delete anything, it just prints "Done" and you swallow all error messages: that's not handling errors, that's covering them. Good luck with that!

I will stay with my version, a little more complex than using an OR but simpler to handle. At least I could known if the rm did in fact delete something or not. As I said in my initial post with great power comes great responsibility

@lokiastari Of course it matters! If it's part of an script you have to handle errors, and your command ends with an error:

/tmp/test$ rm -rf * .*
rm: cannot remove directory: `.'
rm: cannot remove directory: `..'
/tmp/test$ echo $?
1

Whereas my version of rm finishes with a success error code:

/tmp/test$ rm -rf {,.[!.],..?}*
/tmp/test$ echo $?
0

@offirmo, that does not delete hidden files (i.e .htaccess)

Achievements
157 Karma
17,929 Total ProTip Views