Is this safe to use?
sudo rm /Desktop/FILENAME
The reason for wanting to use sudo is I can't see the file.
I accidentally typed in
sudo rm /Desktop/index.html. It didn't find it but could something still have been deleted?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
The slash at the start of
/Desktop would have caused it to look for a
Desktop folder in the root of the filesystem, which almost certainly does not exist, therefore nothing would have been deleted.
In future, keep in mind that both
rm have the ability to be dangerous. You should never need sudo just to manipulate your own files, and if you do need sudo to delete a file, it's generally a file you shouldn't be deleting unless you know what you're doing (there are exceptions, for example it's safe to modify/delete whatever you want in
/srv, etc if you run a server, or
/usr/local if you compile and install your own software, but that's more advanced than general use).
rm, well it doesn't move things into a "Trash" bin for you, so in that sense it's not all that safe, in that it's easy to irrecoverably lose something.
It sounds most likely you were looking in the wrong place, right?
index.html isn't a hidden file (hidden files begin with a dot) so you should be able to see it in your file browser.
No. It most emphatically is not safe. Here's the thing: You can delete files you own without
sudo. If you don't own the file, and you are here asking this question, then you need to ask yourself: "Do I need to delete this file?"
Overuse and consequent misuse of
sudo is one of the banes of Ubuntu.
Never use sudo rm and an absolute url or wildcard if you can help it.
One day you'll have a typo and hate yourself.
~/Desktop as the path as
/Desktop does not exist, the former is the path to your desktop. If it is a single file using
sudo rm ~/Desktop/filename is absolutely fine. Just make ABSOLUTELY SURE you want to delete the file, if it is in your desktop folder and has sudo permissions, ask yourself if it needs to be deleted and if it does, whether you need to make a copy.
"Safe" is an interesting description for anything with sudo. Doing
sudo rm /Desktop/filename will only be "safe" if you wish to delete
filename. It will not delete
/Desktop. Be careful though. I think you mean to use
sudo rm Desktop/filename. This will delete
Desktop from the directory you are currently in. By default there is no
Desktop in your root (
/) drectory. Doing
sudo rm Desktop will even not delete Desktop since it is a directory. If you wish to remove a directory, do
sudo rm -r Desktop. So in a sense, yes, that would be safe. You may not need to use sudo in the first place if it is a file you own (or can access). Be careful with sudo.
The 'rm' command, with or without sudo, is completely safe if you know what you are doing and are careful. If you delete something by accident, it is irrecoverable. (Not entirely true, deleted files sometimes can be retrieved, but I would not rely on it.)
As long as you run exactly that command and that is the file you mean to delete, it is safe. If you use rm (even without root) and you get something wrong (usually with the * wildcard) you could delete all your files. (Of course, you do regular backups, right?)
The real question is why you have a /Desktop folder. You probably mean ~/Desktop.
Anyway, the command is safe. commands like sudo and rm are not inherently dangerous, they just allow you to do stupid things if you type a command wrong. Also, on a single user system, rm is about as dangerous even without sudo, since you probably care more about your personal files than system files.
About your inability to see the file, maybe it's because the filename begins with a '.' and hence is treated as a hidden file. In Ubuntu, you can go Ctrl+h to show hidden files. In the terminal you can type
to show hidden files.
As for the issues with 'sudo' listed above, they are right. Be careful with it. It's better to just delete it, or make it so that you can delete it (chmod/chown) and then just delete it normally. Better safe than sorry :)