How to prevent accidental deletion?

0102

To prevent accidental deletion when using the rm command, you can follow these practices:

  1. Use the -i option: This option prompts you for confirmation before each file is deleted.

    rm -i filename.txt
  2. Use the -I option: This option prompts you once before deleting more than three files or when deleting recursively.

    rm -I *.txt
  3. Use --preserve-root: When using rm -rf, this option prevents the accidental deletion of the root directory.

    rm -rf --preserve-root /
  4. Create aliases: You can create an alias for rm that includes the -i option by adding the following line to your shell configuration file (e.g., .bashrc or .zshrc):

    alias rm='rm -i'
  5. Use a trash command: Instead of rm, use a command that moves files to a trash directory, such as trash-cli or gvfs-trash, which allows for easier recovery.

  6. Regular backups: Maintain regular backups of important files to recover them in case of accidental deletion.

By implementing these practices, you can significantly reduce the risk of accidental deletions.

0 Comments

no data
Be the first to share your comment!