How to say YES to ALL with rm command

The rm command is used to delete files on a Linux system. It can be used to delete a lot of files at once, but you will need to use certain options when trying to delete directories or certain files. In this tutorial, you will learn how to say YES to ALL with the rm command when trying to delete files via the Linux command line.

In this tutorial you will learn:

  • How to say YES to ALL with rm command
How to say YES to ALL with rm command
How to say YES to ALL with rm command
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software rm
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

rm command – say YES to ALL




If you have ended up here, you most likely are trying to delete a lot of files, and do not want to keep getting prompted for confirmation each time. In the examples below, we will go over a few different scenarios in which you may face repetitive prompts, and the solutions to each of these problems.

  1. Likely the only time you should get prompted for confirmation with rm is when you are trying to remove a write protected file.
    $ rm file1
    rm: remove write-protected regular file 'file1'?
    

    In this case, appending the -f (force) option will remove the file (or any number of files) without prompting you for confirmation:

    $ rm -f file1
    
  2. If you are in some odd situation in which you continue to get prompted and cannot add the -f option, you could pipe the yes command to your rm command, like this:
    $ yes | rm file*
    rm: remove write-protected regular file 'file1'? 
    rm: remove write-protected regular file 'file2'? 
    rm: remove write-protected regular file 'file3'? 
    rm: remove write-protected regular file 'file4'? 
    rm: remove write-protected regular file 'file5'?
    

    All of these files are then removed, and this command should finish executing in the blink of an eye.

  3. Note that if you are using the -i (interactive) option, then you will always get prompted for comfirmation before removing a file:
    $ rm -i file1
    rm: remove regular file 'file1'?
    

    The obvious solution to getting rid of these prompts, then, is to simply remove the -i option. This will delete the file without asking you for confirmation first.

  4. In case you need to avoid the error message that comes from attempting to delete a directory, you need to use the -r (recursive) option.
    $ rm -r directory1
    
  5. To delete any kind of file or directory, without ever being prompted, append both the -r and -f options:
    $ rm -rf directory1 file1
    
    NOTE
    You can only delete files or directories that you have proper file permissions on.
  6. In case you need elevated privileges to delete a file, use sudo or log into the root account.


    $ sudo rm file1 file2
    

Closing Thoughts

In this tutorial, we saw how to say YES to ALL when using the rm command on a Linux system. This allows us to bypass the annoying and repetitive prompts that show up when we try to delete a lot of write protected files, or when we forget to turn off the -i switch in our command.