To prevent overwriting files when using the mv command, you can use the -i (interactive) option. This option prompts you for confirmation before overwriting an existing file. Here’s how you can use it:
mv -i testdir/newname.txt ./original_file1.txt
When you run this command, if original_file1.txt already exists, you will be asked to confirm whether you want to overwrite it. You can then choose to proceed or cancel the operation.
Alternatively, you can use the -n (no-clobber) option, which prevents overwriting without prompting:
mv -n testdir/newname.txt ./original_file1.txt
With this option, if original_file1.txt exists, the command will not overwrite it and will simply do nothing.
Feel free to ask if you have more questions!
