PDA

View Full Version : What does "sudo rm -f" do?



curientai
6th January 2008, 06:15 PM
Hi all,

As i was fixing something up on my Mac, the trouble shooting guide asked me to do a "sudo rm -f something else here" at the Terminal. However, by mistake, I entered "sudo rm -f" and hit return. I didn't include anything of something else here. So, does it gonna be a problem? as it doesn't give me any dialog or anything and it just come up with another line for me to enter commands.

I don't know anything about unix commands, so, may I know if I enter "sudo rm -f" and hit enter, does it do any harm? or what does it do?

Thanks in advance. :)

semaja2
6th January 2008, 06:16 PM
If you did had a bit more on that command you would be fracked atm :P that one will wipe your system

Huy
6th January 2008, 06:18 PM
You should never run a command that you don't understand. It could be fatal to your system. ;)

Type "man sudo" into Terminal.
And then "man rm".

Read away :)

The rm utility attempts to remove the non-directory type files specified
on the command line. If the permissions of the file do not permit writ-
ing, and the standard input device is a terminal, the user is prompted
(on the standard error output) for confirmation.


-f Attempt to remove the files without prompting for confirma-
tion, regardless of the file's permissions. If the file does
not exist, do not display a diagnostic message or modify the
exit status to reflect an error. The -f option overrides any
previous -i options.

curientai
6th January 2008, 06:19 PM
If you did had a bit more on that command you would be fracked atm :P that one will wipe your system

I knew that "sudo rm -f /" will doom my system. :p

So, if I just put in "sudo rm -f" and hit return, it won't do any harm?:confused:

Huy
6th January 2008, 06:21 PM
If the invoking user is
root or if the target user is the same as the invoking user, no pass-
word is required. Otherwise, sudo requires that users authenticate
themselves with a password by default (NOTE: in the default configura-
tion this is the user's password, not the root password).


Read the manual entry. :)

bennyling
6th January 2008, 06:21 PM
Well, if you really want to know:

sudo: lets you execute the command as the superuser, ie. root. You usually have to enter your password to be able to continue.

rm: remove. Nuff Said.

the "-f" option when done inconjunction with rm: "Attempt to remove the files without prompting for confirmation, regardless of the file's permissions. If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. The -f option overrides any previous -i options." So in other words, very dangerous to use.

For more information, type "man rm", or "man sudo".

Hope this helped.

curientai
6th January 2008, 06:28 PM
Read the manual entry. :)

Thanks everyone for the rapid replies. :D

Now I understand what sudo, rm and -f means.:)

So, May I conclude that if i just key in "sudo rm -f" and hit return, it would be considered as an incomplete command? and it won't do any harm? :confused:

apologies that I am really stupid on this one...

Huy
6th January 2008, 06:29 PM
Well if it returns you to the prompt (i.e. nothing happened) then you should be okay.

I assume it didn't prompt you for a root (su) password and that you didn't just type in your password... without thinking.


SYNOPSIS
rm -f file

The rm command requires more parameters/arguments that you did not provide, i.e. what files to delete. So it should be fine.

curientai
6th January 2008, 06:33 PM
Well if it returns you to the prompt (i.e. nothing happened) then you should be okay.

I assume it didn't prompt you for a root (su) password and that you didn't just type in your password... without thinking.

The rm command requires more parameters/arguments that you did not provide, i.e. what files to delete. So it should be fine.

:D Thanks mate.

it didn't return anything but the prompt. :) so I think I should be fine. :thumbup:

Thanks everybody. :)

I guess I better study a bit of unix command. :p

Huy
6th January 2008, 06:34 PM
No worries... the command line is very powerful and you shouldn't do anything without knowing the consequences (or reading what these commands actually do ;)).

This should get you started:
Basic UNIX commands
http://mally.stanford.edu/~sr/computing/basic-unix.html

More on Google... :)

Currawong
6th January 2008, 06:42 PM
Returning nothing but the prompt means that the command worked. In UNIX-land, nothing = success and something = failure.

curientai
6th January 2008, 06:43 PM
No worries... the command line is very powerful and you shouldn't do anything without knowing the consequences (or reading what these commands actually do ;)).

This should get you started:
Basic UNIX commands
http://mally.stanford.edu/~sr/computing/basic-unix.html

More on Google... :)

:D actually I just copy and paste that command, I knew that a specific files will be deleted. However, that command is separated in 2 lines, I copied them all, and paste it into the Terminal. I suppose it would join together in one line, but it treated it as 2 different entries. :eek:

I was really scared if I have doom my system. and that's why I asked such a question. :p

indeed, I was solving the bluetooth sync problem with my Windows Mobile based PDA(I use Markspace's Missing Sync), and i looked up their site, and it asked me to :

Type or paste "sudo rm -f
/private/var/root/Library/Preferences/blued.plist" (do not include the
quotation marks) and press return.

From now on, I will investigate every single unix command before i paste them to terminal.:p

Thanks Huy.:D

curientai
6th January 2008, 06:44 PM
Returning nothing but the prompt means that the command worked. In UNIX-land, nothing = success and something = failure.

:eek:Really?

However, i didn't specify any file with this. So what's does it gonna delete?:confused:

i suppose i need to set a parameter so that it would delete?

things like : sudo rm -f / (I know this one would wipe out the entire system)
that's the thing i put in : sudo rm -f No parameter has been set, so I guess I should be fine?

Huy
6th January 2008, 06:46 PM
Yes that is really one long command, and shouldn't be on two separate lines.

Even if that had worked, it wouldn't have been so troublesome (not really, anyway, since it was just a .plist/Preference file).

Check that directory to see if the blued.plist file still exists (use the "cd" and "ls" commands to navigate, "pwd" to tell you where you are if you get lost). That way you can tell whether it worked or not. I suspect it has not, since you didn't copy/paste the command properly (single line, single command).

If you didn't specify the file, nothing gets deleted.

If you did specify the file, it would only be that blued.plist file (that you have specified ;)).

curientai
6th January 2008, 06:51 PM
Yes that is really one long command, and shouldn't be on two separate lines.

Even if that had worked, it wouldn't have been so troublesome (not really, anyway, since it was just a .plist/Preference file).

Check that directory to see if the blued.plist file still exists (use the "cd" and "ls" commands to navigate, "pwd" to tell you where you are if you get lost). That way you can tell whether it worked or not. I suspect it has not, since you didn't copy/paste the command properly (single line, single command).

If you didn't specify the file, nothing gets deleted.

If you did specify the file, it would only be that blued.plist file (that you have specified ;)).

According to the trouble shooting guide, the file will be recreated when I restart OS X. So I suppose it must be there if I check it. Anyways, I have successfully solved the bluetooh sync problem with my PDA.


If you didn't specify the file, nothing gets deleted.
Huy, I am thinking the same too.:D

Brentnal
7th January 2008, 11:18 AM
:eek:Really?

However, i didn't specify any file with this. So what's does it gonna delete?:confused:

i suppose i need to set a parameter so that it would delete?

things like : sudo rm -f / (I know this one would wipe out the entire system)
that's the thing i put in : sudo rm -f No parameter has been set, so I guess I should be fine?

The command you run would of deleted all files in your current working directory. For example, if you were in /Users/ and typed that command, it would delete all files in the users directory. Luckily, you didn't have "rm- rf" which would have done a recursive delete on all files (including sub folders).

curientai
7th January 2008, 11:28 AM
The command you run would of deleted all files in your current working directory. For example, if you were in /Users/ and typed that command, it would delete all files in the users directory. Luckily, you didn't have "rm- rf" which would have done a recursive delete on all files (including sub folders).

If I just enter this command with without defining any directory. what part of the system should get deleted?

that's what I have done in Terminal :
1. Open Terminal from the Utilities folder.
2. sudo killall blued
3. sudo rm -f

I guess I am lucky which I haven't got anything deleted?:confused:

Brentnal
7th January 2008, 08:20 PM
If I just enter this command with without defining any directory. what part of the system should get deleted?


By default the terminal opens to your home directory, when usually contains no FILES, only folders. So I don't think you would have deleted anything.

astr0b0y
7th January 2008, 09:03 PM
By default the terminal opens to your home directory, when usually contains no FILES, only folders. So I don't think you would have deleted anything.

Exactly. To delete directories, add the switch -r (recursive).

curientai
8th January 2008, 09:52 AM
Exactly. To delete directories, add the switch -r (recursive).

Lovely :) so I didn't lose anything :D. Thanks Astr0b0y and Brentnal for additional clarification. ;)

Katey
29th March 2008, 01:27 AM
Heres a youtube vid of sudo rm -rf /

YouTube - sudo rm -rf / in OS X (http://www.youtube.com/watch?v=7RfihcLJLeo)

Fairly amazing the OS is still running after it finishes.

mab
29th March 2008, 02:29 AM
The command you run would of deleted all files in your current working directory. For example, if you were in /Users/ and typed that command, it would delete all files in the users directory. Luckily, you didn't have "rm- rf" which would have done a recursive delete on all files (including sub folders).

rm -f without the second argument wont do anything

eg

$ls -l
$touch test
$ls -l
-rw-r--r-- 1 mab staff 0 29 Mar 01:52 test
$rm -f
$ls -l
-rw-r--r-- 1 mab staff 0 29 Mar 01:52 test
rm -f test
$ls -l