Sunday, May 20, 2012

UNIX Command To Rename A File

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

No comments:

Post a Comment