How to enable a confirmation on deleting files?

My girlfriend was super upset because she accidentally moved an important document of hers to the trash bin.

I recovered the document, so no harm done, but how can I get a confirmation dialog before a file is moved to the trash bin?

I think I've done the same on Ubuntu a couple of times and it's simply too easy to accidentally delete files.

1 Like

This is one of the features that has been removed from Nautilus File Manager (Files) by the Gnome Devs.

This is also problematic because while you can right click and send to trash, you can also drag and drop to trash.
I have just written and tested three different scripts included in the summary below... and not a single one worked in Nautilus.

Summary
#!/bin/bash

destination_directory="$2"

if [ "$destination_directory" == "~/.local/share/Trash/files" ]; then
    read -p "Are you sure you want to move $1 to the trash? (y/n) " answer
    if [ "$answer" == "y" ]; then
        /bin/mv "$1" "$destination_directory"
        echo "File moved to trash."
    else
        echo "Operation canceled."
    fi
else
    /bin/mv "$1" "$destination_directory"
    echo "File moved to $destination_directory."
fi
#!/bin/bash

destination_directory="$2"

if [ "$destination_directory" == "~/.local/share/Trash/files" ]; then
    read -p "Are you sure you want to move $1 to the trash? (y/n) " answer
    if [ "$answer" == "y" ]; then
        /bin/mv "$1" "$destination_directory"
        echo "File moved to trash."
    else
        echo "Operation canceled."
    fi
else
    /bin/mv "$1" "$destination_directory"
    echo "File moved to $destination_directory."
fi
#!/bin/bash

destination_directory="$HOME/.local/share/Trash/files"

if zenity --question --text="Are you sure you want to move $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS to the trash?"; then
    mv "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" "$destination_directory"
    zenity --info --text="File moved to trash."
else
    zenity --info --text="Operation canceled."
fi

You might have more luck trying them... You will need to name the file and save it in a place (I used trash-confirm.sh), make it executable, and then set the path to that location for move using a symlink:

chmod +x /path/to/trash-confirm.sh

sudo ln -s /path/to/trash-confirm.sh /usr/local/bin/mv

That being said, I use Nemo File manager and under Preferences > Behavior > Trash there is a checkbox for "ask before moving files to trash"
I clicked that, then tested it: Worked perfectly.

So using Nemo File Manager might be an option for you.

sudo apt install nemo

NOTE: if you want the version Nemo 5 (which includes a newer better search ability), follow this post on how to install it. Be sure to remove the repository once you install Nemo. You Must Remove The Repository before doing anything else.

Use This to Make Nemo Default.

1 Like

I think GNOME team removed the removal confirmation because on Nautilus preferences on the Behavior section they set 2 trash bin options that prevent a definitive file deletion, that are confirming trash bin emptying and showing a request for definitive deletion. This way you both make order on your folders by moving files to the trash bin immediately without an additional request and even be sure that you can restore files if you need them again.

Also consider including snapshot of your /home folder when using Timeshift which is excluded by default.

GDay @WillItBlend , Welcome to the community!

If your using Zorin Core (Gnome), first open the "Rubbish Bin" directory.
Next click the "Hamburger" Icon in the top right hand corner & select "Preferences", on the prefernce page click "Behaviour" at the top.
Then place a tick in the "Ask Before emptying the rubbish bin"
Hope this helps.

Hope this helps.

  • Could we as you to update your profile to show which Edition of Zorin OS your using... this save us asking in the future, Thank you.
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.