What happens if the destination exists?

QuestionsQuestions8 SkillsProDec, 17 2025
0116

That's a great question!

If the destination file (in your example, original_file1.txt) already exists in the target directory (the current directory ./), the mv command will overwrite the existing file with the new file being moved (newname.txt) without asking for confirmation.

This is an important behavior to remember when using mv, as it can lead to unintentional data loss if you're not careful.

If you want to be prompted before overwriting an existing file, you can use the -i (interactive) option with mv, like this:

mv -i testdir/newname.txt ./original_file1.txt

This would ask you for confirmation before overwriting original_file1.txt if it already exists.

Does that clarify what happens in such a scenario?

0 Comments

no data
Be the first to share your comment!