To avoid overwriting files when using the mv command, you can use the -i (interactive) option. This prompts you for confirmation before overwriting an existing file. Here’s how to use it:
mv -i testdir/newname.txt ./original_file1.txt
What Happens:
- If
original_file1.txtalready exists, the terminal will ask you if you want to overwrite it. You can then choose to proceed or cancel the operation.
Additional Options:
-
-n(no-clobber): This option prevents overwriting files without prompting. If the destination file exists, the command will not perform the move.mv -n testdir/newname.txt ./original_file1.txt
Using these options helps protect your files from accidental loss. If you have any more questions or need further assistance, feel free to ask!
