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?
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?
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.
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 sudo and 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 /var/www or /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).
As for 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.
sudo is okay to install stuff not to delete - not exactly. sudo at any time gives you the ability to do damage to your system more easily, so in that sense it's not "safe". But when installing new software via the console it is "necessary". When managing your own files, sudo should never be necessary. Also "rm" is only unsafe in the sense that it wipes files without storing them into trash. If you're not confident using console based tools you can use the relative safety of the desktop with its file managers and software centre.
– thomasrutter
Jul 25 '14 at 02:05
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.
sudo you can't also do without. In fact, files you can only delete with sudo generally come straight from the distribution and are therefore trivial to restore, whereas user files will in the worst case be irretrievable (of course you should properly use version control and off-site backups, but way too many people don't). — Nevertheless: it's definitely a bad habit to throw in sudo just to get your sandwiches! Last time I dded over the wrong hard drive, I did hate myself...
– leftaroundabout
Jul 24 '14 at 23:19
files you can only delete with sudo generally come straight from the distribution and are therefore trivial to restore - I would strongly disagree with this. First, knowing what package to reinstall is not for beginners. And there are many root-owned files which if deleted will render the system unable to install packages, or to boot, or create other hard to diagnose problems.
– thomasrutter
Jul 25 '14 at 00:46
Use ~/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.
~/Desktop when it's not strictly clear that that's the directory he wanted to delete is not very good, I think.
– Volker Siegel
Nov 02 '14 at 10:42
"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 filename under 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.
sudo and safe in the same sentence.
– Kaz Wolfe
Sep 22 '14 at 04:21
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.
rm is like a loaded gun. Treat it with utmost care and maybe you won't shoot yourself. With sudo rm it's like you can shoot your roommates too or fire a rocket against your house.
– hmayag
Jul 24 '14 at 22:54
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
ls -a
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 :)
sudoprivileges so you can run any command likelsorcatorless- even open it in a GUI editor through the terminal. – hmayag Jul 24 '14 at 23:05sudo. Always be suspicious if something tells you to use sudo just for doing something you would normally be able to do on any computer, such as managing your own files. – thomasrutter Jul 25 '14 at 00:54-vso you'd see what you are deleting or-viso it would ask for confirmation – Tymric Jul 25 '14 at 10:56rootcan not do everything. For example, if a file is owned by root but has permissions000, this means the owner (root) can not read it, write it, or execute it. Forrootnot to be able to see it, either, I believe the folder has to be000, as well. – trysis Jul 26 '14 at 13:34lswill list it. I just got a warning fromrmthat the file way protected, typedyand hit enter and the file was gone. Oh, and nothing stopped me fromchmod-ing it back to 777, so I guessrootcan do everything after all :-) – hmayag Jul 26 '14 at 20:47000, as well? If you do this, I believe you can't see anything inside the folder, but you can see the folder itself. To not see the folder, you need tochmodthe folder of that folder to000, and so on. I'm sure you can make/(the filesystem's root folder)000, but I'm not sure if it'll finish the command, and, even if you manage it, you won't be able to do anything on that computer anymore. – trysis Jul 27 '14 at 04:06rmthe file, even though you were unable to read, write, or execute it, was because deleting a file depends on the folder, as well. I believe it requires write permission. – trysis Jul 27 '14 at 04:10rootcan not do everything." In that regard even the fringe situation you describe of setting/permissions to000can be reversed by booting a live system, mounting the problematic partition andchmod-ing your way through the directory structure (I'm not saying it's easy, but it's doable). In the context of the OP, a simplesudo ls -lwould have revealed if the offending directory had restrictive permissions andsudo chmod 777 /Desktopwould have granted full access to it. – hmayag Jul 27 '14 at 10:05/Desktophad low permissions and was owned by root). Then, you seemed interested, so I commented some more. Probably went overboard a little, but that's why I said all that. That's interesting about the live system, though, I guess root can do pretty much everything, after all. – trysis Jul 27 '14 at 16:16gksudo nautilus ~. Then press Ctrl+H. This will let you see ALL existing files in the filesystem, with a GUI. If you asked to install gksudo, typesudo apt-get install gksudo -yand let it roll. gksudo is a GUI front-end for sudo that everybody needs to have. It's like sudo, but preferred for GUI programs. – John Scott Aug 13 '14 at 00:29