I’ve just seen the title of this post in my blog stats as search-term hit to my blog, and while they guy searching didn’t find his answer here (He got directed to my Nautilus Garbage Bin post), I decided to make sure the next one searching for that will find a decent answer.
I must admit that I firmly believe that root’s work should be done from the command-line, however, if a guy insists on doing it this way, well so be it, this is, after all, Linux, the OS of the free…
So basically I can see 2 ways of going about deleting files as root with Nautilus:
- Run the entire Nautilus with gksudo.
- Using a Nautilus script to run the rm command with root permissions (again, using gksudo)
While the first method seems to be fairly straight-forward, I’d recommend against it, Nautilus is a huge hunk of code, exactly the wrong thing to be running as root, you don’t want to hose your system because of some nautilus bug, do you? this can also have all kinds of other unexpected side-effects such as having image thumbnails created in the user’s home directory with root file permissions, thereby disabling the user from removing them easily.
In order to accomplish deleting files with the 2nd method, one needs to write a Nautilus script and place it in the “.gnome2/nautilus-scripts” directory in his home directory, I’ve provided an example for such a script here.
To install and use my script you don’t need to go to the command line, just follow the following simple steps:
- In Nautilus, type ctrl+L to present the location bar.
- In the location bar, type “~/.gnome2/nautilus-scripts” and press the “Enter” key, this will take you to the Nautilus scripts directory.
- In the directory, right-click on a blank space and select “Empty File” from the “Create Document” sub menu.
- Give a meaningful name to the file you’ve just created, for example, “delete_as_root.bash”, the name will later appear as an entry in Nautilus` right-click menu.
- Right click the file and select “Open with Text Editor”, this will open the file for editing in your preferred text editor, which would probably be Gedit, unless you configured your system otherwise.
- Copy and paste the script from my site into the Editor, take care to copy all and only the numbered script lines.
- Delete the line numbers, I’ve put then there to make it easy to discuss the scrip, but it won’t run with them inside, make sure you don’t leave spaces before the beginning of the actual text in the lines.
- Save the file and exit the editor.
- Right click the file, select “Properties” and check the “Allow executing file as program” check box in the Permissions tab.
- Thats it! in a few minute you’ll find a new “Scripts” sub menu, when right-clicking a file in Nautilus, that menu should contain the name of the file you’ve just created, clicking it will run the script and delete the file or files you currently have selected in the Nautilus window.
- If you’re impatient, an can’t wait until the script will appear on it own, you can log out back into you user account.
If this seems to you like a rather long and tedious process, I must agree, this could be done a whole lot faster from the command line, but hey, if we wanted to use the command line here we would’ve just “sudo rm”-ed the files in the first place and be done with…