How to avoid overwriting files?

QuestionsQuestions8 SkillsProBasic Files OperationsSep, 06 2025
0162

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.txt already 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!

0 Comments

no data
Be the first to share your comment!