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.

link|improve this question

rm -f, yes | rm and so on, but this belongs to SU. – khachik Oct 12 '11 at 19:30
1  
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 (./foo.sh) or sourcing it (. foo.sh or source foo.sh)? – Keith Thompson Oct 12 '11 at 19:56
feedback

migrated from stackoverflow.com Oct 12 '11 at 20:18

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

6 Answers

up vote 6 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.

link|improve this answer
1  
Alternatively, use command rm ... or \rm ... to skip the alias/function – glenn jackman Oct 12 '11 at 20:26
1  
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
feedback

The force flag removes all prompts;

rm -f

link|improve this answer
feedback

May the force be with you - rm -f

link|improve this answer
feedback

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).

link|improve this answer
feedback

If you have the required permissions to delete the file and you don't want to be prompted do the following :

rm -f file

-f = force

Otherwise you will need to use :

sudo rm -f file

If you don't have permissions to the file.

link|improve this answer
1  
The "remove regular file?" prompt implies that it's not a permissions problem. – Keith Thompson Oct 12 '11 at 21:23
feedback

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)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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