How do you rename a file using the 'mv' command?

To rename a file using the mv command, you specify the current name of the file as the source and the new name as the destination. Here’s the syntax:

Syntax:

mv current_filename new_filename

Example:

If you want to rename a file called oldname.txt to newname.txt, you would use:

mv oldname.txt newname.txt

Steps:

  1. Open your terminal.
  2. Navigate to the directory containing the file (if necessary) using the cd command.
  3. Run the mv command with the current and new file names.

Important Note:

  • If newname.txt already exists, it will be overwritten without any prompt unless you use the -i option for interactive mode:
    mv -i oldname.txt newname.txt

This command effectively renames the file in the same directory.

0 Comments

no data
Be the first to share your comment!