How can the mv command be used to move files interactively?

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.txt already exists, you will see a prompt asking:
mv: overwrite 'backup/file.txt'? 
  • You can then respond with y (yes) to overwrite or n (no) to cancel the move.

Using the -i option helps prevent accidental data loss by requiring your confirmation before overwriting files.

0 Comments

no data
Be the first to share your comment!