mv move file

mv [options] source destination

mv command syntax

$ mv [options] source dest

mv command options

mv command main options:

option description
mv -f force move by overwriting destination file without prompt
mv -i interactive prompt before overwrite
mv -u update – move when source is newer than destination
mv -v verbose – print source and destination files
man mv help manual

mv command examples

Move main.c def.h files to /home/usr/rapid/ directory:

$ mv main.c def.h /home/usr/rapid/


Move all C files in current directory to subdirectory bak :

$ mv *.c bak


Move all files in subdirectory bak to current directory :

$ mv bak/* .


Rename file main.c to main.bak:

$ mv main.c main.bak


Rename directory bak to bak2:

$ mv bak bak2


Update – move when main.c is newer:

$ mv -u main.c bak


Move main.c and prompt before overwrite bak/main.c:

$ mv -v main.c bak
‘bak/main.c’ -> ‘bak/main.c’


To rename a file:

   mv junk precious

This renames the file junk as the file precious.

To be prompted when using the mv command:

    mv -i draft1.txt part1.txt
    remove part1.txt? n

This command prompts you to confirm that you really want to move the file draft1.txt to the file part1.txt; a file with that name already exists.

Entering n cancels this action: a y confirms it.

To move a file to another directory:

    mv precious treasure

This moves the file precious from the current directory to the directory treasure.

To move a file to another directory and rename it:

   mv jewel casket/amethyst

This moves the file jewel to the filename amethyst in the subdirectory casket.

To move and rename a directory:

   mv vr1.1 ../environments/virtual_rooms

This moves the directory vr1.1 from the current directory to the directory ../environments and renames it as virtual_rooms.