How to enable a confirmation on deleting files?

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