UNIX Command To Rename A File

by Vivek Gite · 0 comments

How do I rename a file in UNIX?

The mv is a Unix command that renames one or more files or directories. The original filename or directory name is no longer accessible. Write permission is required on all directories and files being modified.

mv Syntax

You need to use the mv command to rename a file as follows:

mv old-file-name new-file-name

Examples

Open the terminal (bash shell prompt) and type the following command to list file names:

ls
ls -l

In this example, rename a file called data.txt to letters.txt, enter:

mv data.txt letters.txt
ls -l letters.txt

File is renamed so the following command will display an error on screen:

ls -l data.txt

Outputs:

ls: cannot access data.txt: No such file or directory

Suggested Readings:

Type the following command to read mv command man page:
man mv

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All