Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This may be a silly question, but I can't seem to run rm from a bash script and remove a file.

rm -rf myjunk.out
exit 0;

doesn't remove myjunk.out

share|improve this question
Get rid of the exit 0 and check for error messages. – ChrisF Feb 10 '11 at 23:31
And it DOES work when you just execute rm -rf myjunk.out from the command line? What is triggering execution of this script? – BloodPhilia Feb 10 '11 at 23:34
Just for the record, -r is meant to descend on directories (Recursive), so if you intend to remove a file, -r is futile. What error do you get ? How do you run this script ? What are the permissions on this script ? – Torian Feb 11 '11 at 1:48
@BloodPhilla it's triggered because myjunk.out is generated earlier in the script.... @Torian -r was in there because I was just trying stuff out – CamelBlues Feb 11 '11 at 18:28
up vote 2 down vote accepted

First, make sure that you can delete myjunk.out without running your script; if not, check file attribute with lsattr.

Second, You don't need to providing exit 0;

Later, point a path to myjunk.out, such as:

rm -rf /path/to/myjunk.out
share|improve this answer
Also remove the -r flag. it is unnecessary and dangerous. – Keith Feb 11 '11 at 2:17
Actually, taking out the exit 0; allowed rm installed.out to execute properly. Thanks! – CamelBlues Feb 11 '11 at 18:29
What is the explanation of : Why the "exit 0" will make the rm not working – Emmanuel Devaux Feb 11 '14 at 10:01

Remove all options -f is dangerous:

-------------- man page ---------------------------------------------

Attempt to remove the files without prompting for confirmation, regardless of the file's permissions. If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. The -f option overrides any previous -i options.

The bold (mine) part is self explanatory. Before to use commands like rm first type man rm

RTFM is a wise advice

share|improve this answer
This is more of a comment than an answer. – Chenmunka Jan 25 at 15:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.