Search

Linux mv command howto

The Linux mv command is used to move a file from one location to another location. The mv command can also be used to rename a file. The syntax of Linux "mv" command is

mv [options] source target

If the target argument is a directory, mv moves the source files into that directory without changing the file name. Only regular files can be moved across filesystems.

Example: The following command can be used to rename the file install.log to be install.log.bak.

[root@RHEL01 logs]# mv install.log install.log.bak

The main difference between mv and cp is in what happens with (update time, inode number, etc.). mv retains the inode number and the inode. cp creates an entirely new file with new inode information, changing only the filename and access time.

 

 

Option

 

Description

b, --backup

Create backups of files that are about to be overwritten.

-f, --force

Overwrite existing target files without prompting the user.

-i, --interactive

 

Prompt the user before overwriting a target file.

-u, --update

In the case where a target file has the same name as the source and the target file's most recent modification time is more recent than that of the source, do not move.

-v, --verbose

Verbose mode

-S SUFFIX,

In the case where use of the -b option generates a backup file, append SUFFIX to the filename of each backup file created.

Related Tutorials