To use the mv command interactively, you can include the -i option. This will prompt you for confirmation before overwriting any existing files in the destination.
Syntax:
mv -i source_file destination/
Example:
If you want to move file.txt to a directory called backup, and you want to ensure you don't accidentally overwrite an existing file, you would use:
mv -i file.txt backup/
Behavior:
- If
backup/file.txtalready exists, you will see a prompt asking:
mv: overwrite 'backup/file.txt'?
- You can then respond with
y(yes) to overwrite orn(no) to cancel the move.
Using the -i option helps prevent accidental data loss by requiring your confirmation before overwriting files.
