Is there any difference in power between sudo rm and sudo rm -f?

2

Simple question, but I'm not sure I got a complete understanding from man rm. To the best of my knowledge the only difference is that adding the -f will plow through files without prompting and without regard to their writeability, but is there any way to create a file or directory so that sudo rm will fail to remove it but sudo rm -f won't?

Joshua Snider

Posted 2015-01-21T22:19:29.567

Reputation: 121

A detailed explanation of the rm command is available here: The rm Command

– Vinayak – 2015-01-21T22:32:12.083

Answers

0

It is not only the matter of understanding rm, but you should also be familiar with what the sudo does. Rm is a command to delete files and directories (with proper options), sudo changes the scope of user rights (you run the command with other user privileges). If you type sudo rm, you are running the rm command with root privileges instead of your user ones.

So the answer can be:

  • "rm -f *" -> delete all files in current directory which you have rights to without asking. That means all files that belongs to you or the group you are member. This command omits all directories in current directory. If you need to delete everything, use rm -rf instead.

  • "sudo rm *" -> delete all files in current directory and ask if you really want to do it when some of the files are without write permissions. If you want to delete every file (not directory, as mentioned before), you should add the option -f. It doesn't matter who owns the files in this directory this time, because you are acting as root (linux administrator).

It is not therefore possible to create a file or directory which can not be removed by sudo rm and can be removed by rm. The superuser (root) can do everything.

Houmles

Posted 2015-01-21T22:19:29.567

Reputation: 1