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
|Requirements, Conventions or Software Version Used
|Any Linux distro
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – 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.
- Likely the only time you should get prompted for confirmation with
rmis 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
- If you are in some odd situation in which you continue to get prompted and cannot add the
-foption, you could pipe the yes command to your
rmcommand, 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.
- 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
-ioption. This will delete the file without asking you for confirmation first.
- In case you need to avoid the error message that comes from attempting to delete a directory, you need to use the
$ rm -r directory1
- To delete any kind of file or directory, without ever being prompted, append both the
$ rm -rf directory1 file1
You can only delete files or directories that you have proper file permissions on.
- In case you need elevated privileges to delete a file, use
sudoor log into the root account.
$ sudo rm file1 file2
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.