Stardust

Safely Remove Files In Linux

curl -O https://stardustziggy.com/rm.sh
chmod +x rm.sh
./rm.sh

Curl to download the script, chmod to make it executable and ./ to execute.
This script avoid deleting ‘.’ and ‘..’ and asks for confirmation after presenting a list of files to delete.

The script:

#!/bin/sh
echo “This is the directory you are going to delete: $PWD? If you type ‘Yes’ you’ll see a list of the files for confirmation. Type ‘q’ to quit the list.”
read klk
if [[ $klk == “yes” || $klk == “Yes” || $klk == “YES” ]]; then
       find * -xdev -type f|less
       echo “Ok, the files on the list will be gone, is that OK? ‘Yes’ to proceed.”
       read klk2
       if [[ $klk2 == “yes” || $klk2 == “Yes” || $klk2 == “YES” ]]; then
               find * -xdev -type f -exec rm -rf ..?* .[!.]* {} +
               echo “Ok, files were deleted from $PWD.”
       else
       echo “Better safe than sorry. Bye.”
       fi
else
       echo “Well, see you later!”
fi

 

That’s all folks, see you  later!

Leave a Reply

Your email address will not be published. Required fields are marked *