What if the new name exists?

QuestionsQuestions8 SkillsProBasic Files OperationsOct, 07 2025
077

If the new name you specify already exists when using the mv command, it will be overwritten without any warning. This means that the contents of the existing file will be replaced by the contents of the file you are moving or renaming.

To Prevent Overwriting:

You can use the -i option (interactive mode) with the mv command. This will prompt you for confirmation before overwriting an existing file.

Example:

mv -i file1.txt newname.txt

If newname.txt already exists, you will see a prompt asking if you want to overwrite it. You can then choose to proceed or cancel the operation.

Summary:

  • Without -i: Overwrites the existing file without warning.
  • With -i: Prompts for confirmation before overwriting.

If you have more questions or need further assistance, feel free to ask!

0 Comments

no data
Be the first to share your comment!