When should the '-i' option be used with the 'mv' command?

The -i option should be used with the mv command when you want to prevent accidental overwriting of existing files. Here are some scenarios where using -i is beneficial:

  1. Preventing Data Loss: If you are unsure whether the destination file already exists, using -i will prompt you for confirmation before overwriting it.

  2. Working with Important Files: When moving or renaming critical files, the -i option adds a layer of safety by ensuring you explicitly confirm any overwrites.

  3. Batch Operations: If you are moving multiple files and are unsure about the contents of the destination directory, using -i can help you avoid unintentional data loss.

Example:

mv -i file.txt backup/

If backup/file.txt exists, you will be prompted:

mv: overwrite 'backup/file.txt'?

Using the -i option is a good practice when you want to ensure that you do not accidentally overwrite important files.

0 Comments

no data
Be the first to share your comment!