Nautilus does not provide a confirmation option: solution?
The fact that nautilus does not provide an option, does not mean that you have to take the risk to accidentally lose files if you unintentionally (and unnoticed) hit the Enter key.
You can simply run a script in the background, keeping an eye on delete actions, using the
trash-cli -tools. If you run the script below in the background, it does two things that will prevent unnoticed deletion
It notifies you whenever you move a file to trash:
If you click "OK", nothing happens. If you click "Cancel", the trash will be opened and you can restore your item, since you know the name and the original path to the file.
It keeps track of the last 50 trash actions (one per line)
In your Home directory, the script creates a log file,
trashlog.txt, with the last 50 trash actions. This makes sure that you can track what happened, even if you accidentally hit the "OK" button.
It logs all trash events with a time stamp, like:
Tue Feb 24 07:30:55 2015: '/home/jacob/Naamloze map/Naamloos document (11e kopie)'
Tue Feb 24 07:31:09 2015: '/home/jacob/Naamloze map/Naamloze map'
In a loop, the script checks the list of deleted files with the help of
trash-cli, with the command:
The command lists all delete actions, also from e.g. external drives.
Whenever new items appear in the list, the script calls a Zenity window, listing the (newly) deleted files. At the same time, these files are listed into a log file:
~/trashlog.txt. To prevent the file to become to large, it only "remembers" (a little more then) the last 50 delete events.
The Zenity window returns a "non-zero" when the
Cancel button is pressed, and the script opens
trash:///) to enable the user to restore the file.
How to use
The script uses
sudo apt-get install trash-cli
Copy the script below into an empty file, save it as
trash_secure (no extension) in
~/bin. Make the directory if it does not exist yet.
- Make the script executable.
Log out and back in, test-run the script from a terminal eindow with the command:
If all works fine, add it to your Startup Applications: Dash > Startup Applications > Add.
home = os.environ["HOME"]
trashlog = home+"/trashlog.txt"
if not os.path.exists(trashlog):
with open(trashlog, "wt") as log:
with open(trashlog, "r") as log:
log = log.readlines()
log = log[50:]+[last_trashed] if len(log) > 50 else log+[last_trashed]
with open(trashlog, "wt") as out:
for it in log:
trash1 = trashlist()
trash2 = trashlist()
if trash2 != trash1:
diff = (" ").join(["'"+l[l.find("/"):]+"'" for l in trash2.splitlines() if not l in trash1])
zenity_message = "zenity --list --width=600 --height=200 --title='Items were trashed' --text='' --column='Path' "+diff
check = subprocess.check_output(["/bin/bash", "-c", zenity_message]).decode("utf-8")
if check != "":
trash1 = trash2
- The script also tracks trash actions from possibly attached external drives. If one of these drives has a space in its name, the script will break. I had to rename my external drive, named "My Passport", to give an example. That is not caused by the script itself, but by the
trash-cli tools the script uses.
- The most elegant way would be (of course) to directly "untrash" the files if you pressed "Cancel". The
trash-cli tools do not provide an option to do that from the command line however, other than an interactive one.