Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

ubuntu 9.10 if you type rm you get a missing operand error, same thing with rm -r but rm -f yields no error. -f is supposed to be 'force' not 'dispell errors'

share|improve this question
up vote 8 down vote accepted

From the Unix manpage

-f, --force
ignore nonexistent files, never prompt

ignoring nonexistant files means that there will be no error if there is no files to remove, which is what happens when you use rm -f with no file(s) specified. This is the expected behavior as far as I know. It does not ignore all errors, but -f does not require the file to be listed an operand, so there is no error to throw.

share|improve this answer
seems a little fishy to me, The man page says this: rm [OPTION]... FILE... as in FILE is not optional. – Stu Jul 7 '10 at 15:04
@nixomose unless -f is specified :). The point is that you can specify multiple files on the command line. If any one of them is missing and you didn't pass -f, you get an error. If you do pass -f, any errors related to files are suppressed. – Felix Jul 7 '10 at 18:50
right, that's what happens, but that's not what the man page leads you to believe. -f, --force ignore nonexistent files, never prompt Say nothing about ignoring errors. – Stu Jul 7 '10 at 20:19
+1 for nixomose, " but -f does not require the file to be listed an operand" is plain non-sense. The man page you link to claims no such thing and actual explicitly declares it as required. This is simply a case of the man page and program behavior not matching. The man page needs to be updated to more accurately reflect the effect of the 'f' switch – Dan McGrath Jul 7 '10 at 22:46
+1 for Dan McG - I concur. – JT.WK Jul 7 '10 at 22:54

SUSv3 says:

-f Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of nonexistent operands. Any previous occurrences of the -i option shall be ignored.

share|improve this answer

To understand why the file parameter is really optional, you have to consider that in many scripts the list of files to remove is stored in a variable and using -f allows you to not care whether the list is empty or not. You can simply do:

rm -f $FILES

insead of the more cumbersome:

-z "$FILES" || rm $FILES

So it's logical that an option called "ignore nonexistent files" does not fail when no file is given on the command line.

share|improve this answer
This may be true and make sense and programmers tend to do what's personally convenient more than what follows the pattern, but this is 'rm'. It's older than my dad and the man page has been wrong for how many decades? – Stu Jul 8 '10 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .