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:
- Open your terminal.
- Navigate to the directory containing the file (if necessary) using the
cdcommand. - Run the
mvcommand with the current and new file names.
Important Note:
- If
newname.txtalready exists, it will be overwritten without any prompt unless you use the-ioption for interactive mode:mv -i oldname.txt newname.txt
This command effectively renames the file in the same directory.
