Yes, there are safer alternatives to rm -rf that can help prevent accidental deletions. Here are a few options:
-
Using
rm -rwith confirmation:
You can use the-ioption to prompt for confirmation before each file is deleted:rm -ri directory-name -
Using
trash-cli:
You can installtrash-cli, which moves files to the trash instead of permanently deleting them:sudo apt install trash-cli trash directory-name -
Using
findwith-delete:
You can use thefindcommand to selectively delete files:find directory-name -type f -exec rm -i {} \;This will prompt for confirmation before deleting each file.
-
Using a GUI file manager:
If you're using a graphical interface, you can use a file manager to delete directories, which often includes a confirmation dialog.
These methods provide an extra layer of safety compared to using rm -rf.
