Safer alternatives to the rm -rf command include:
-
Using
rmwithout-f: This prompts for confirmation before deleting files.rm -r directory_name -
Using
trash-cli: This tool moves files to a trash/recycle bin instead of permanently deleting them.sudo apt install trash-cli trash directory_name -
Using
findwith-delete: This allows for more controlled deletions, especially when combined with conditions.find directory_name -type f -name "*.tmp" -delete -
Creating a backup: Before deleting, create a backup of important files or directories.
cp -r directory_name backup_directory_name -
Using
rm -i: This option prompts for confirmation before each file is deleted.rm -ri directory_name
These alternatives help prevent accidental data loss and provide a safety net when deleting files and directories.
