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

How can I remove file without asking user if he agrees to delete file? I am writing shell script and use rm function, but it asks "remove regular file?" and I really don't need this. Thank you.

share|improve this question

migrated from Oct 12 '11 at 20:18

This question came from our site for professional and enthusiast programmers.

rm -f, yes | rm and so on, but this belongs to SU. – khachik Oct 12 '11 at 19:30
rm doesn't show a "remove regular file?" prompt by default. You must have it aliased to rm -i, or defined as a function. I'm surprised that the alias is visible inside your script. Are you executing the script (./ or sourcing it (. or source – Keith Thompson Oct 12 '11 at 19:56
up vote 53 down vote accepted

You might have rm aliased to rm -i so try this:

/bin/rm -f file.log

To see your aliases you can run alias.

share|improve this answer
Alternatively, use command rm ... or \rm ... to skip the alias/function – glenn jackman Oct 12 '11 at 20:26
It's been argued that having rm aliased to rm -i is a bad idea. The rm command, by default, silently removes the named file. By aliasing it to rm -i, you can get into the habit of not checking carefully before pressing Enter, depending on the interactive prompt to save you. Then you type rm some-important-file in an environment without the alias. – Keith Thompson Oct 12 '11 at 21:25
@Keith That is very true, i only personally alias rm to rm -v – chown Oct 12 '11 at 21:33
If "rm" is a function (instead of an alias), this answer should work. And the bash unset command might be interesting – Xen2050 Feb 25 '15 at 14:15

The force flag removes all prompts;

rm -f

share|improve this answer
This is what I am looking for, not the accepted answer. – gsamaras Dec 14 '15 at 13:12

May the force be with you - rm -f

share|improve this answer

Within a shell script, you would want to use rm -f <filename> but you also have the option of getting rid of the implicit -i option for your environment by entering unalias rm in your shell (or profile).

share|improve this answer

If you have the required permissions to delete the file and you don't want to be prompted, do the following (-f = force):

rm -f file

If you don't have permissions to the file, you will need to use:

sudo rm -f file
share|improve this answer
The "remove regular file?" prompt implies that it's not a permissions problem. – Keith Thompson Oct 12 '11 at 21:23

the yes program repeatedly replies yes to any prompts. so you can pipe it into the interactive rm program to get the desired effect too.

yes | rm <filename>

conversely, if you want to not do something interactive, you can do

yes n | <something interactive>

and that will repeat 'n' on the input stream (effectively answering no to questions)

share|improve this answer
The yes n option is not working for me. While I use yes n | rm file.txt, it actually removes the file even though the file is right protected. – iammilind Dec 8 '15 at 6:07

Currently I am working at a system, where the bash shell recieved the definition of the rm command as a function in one of the global configuration files:

 rm  () { /bin/rm -i ${1+"$@"}; }

Hence, none of the above answers regarding aliases did work. To counter the annoying behaviour I unset the rm function in my .bashrc file

 unset -f rm

I had a similar problem then the opener. However I did not found any answer that mentioned the possibility that rm is hidden by a shell function. So I added the answer here in the hope it would be of help for somebody facing the same type of problem.

Typing /bin/rm or rm -f all the time is inconvenient, and may have bad consequences (in the case of rm -f).

share|improve this answer
That may have solved your problem but it does not answer the question. – suspectus Feb 25 '15 at 13:57
Wouldn't the selected answer - calling /bin/rm work? If I have a function in bash, and an executable file with the same name in the current directory, just adding ./ in front of the name will call the file - not the function. PS - I added a comment to the selected answer about a function & unset – Xen2050 Feb 25 '15 at 14:12
Yes, /bin/rm works. Doing the unset removes the need for typing the full path. – daw Feb 25 '15 at 16:03

You must log in to answer this question.

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