Are there safer alternatives to rm -rf?

QuestionsQuestions8 SkillsProBasic Files OperationsOct, 18 2025
0160

Yes, there are safer alternatives to rm -rf that can help prevent accidental deletions. Here are a few options:

  1. Using rm -r with confirmation:
    You can use the -i option to prompt for confirmation before each file is deleted:

    rm -ri directory-name
  2. Using trash-cli:
    You can install trash-cli, which moves files to the trash instead of permanently deleting them:

    sudo apt install trash-cli
    trash directory-name
  3. Using find with -delete:
    You can use the find command to selectively delete files:

    find directory-name -type f -exec rm -i {} \;

    This will prompt for confirmation before deleting each file.

  4. 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.

0 Comments

no data
Be the first to share your comment!