Safely Remove Files In Linux

curl -O
chmod +x

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:

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.”
       echo “Better safe than sorry. Bye.”
       echo “Well, see you later!”


That’s all folks, see you  later!

Leave a Reply

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