Linux mv Example: Move Files or Directories to Another Directory – Linux Tutorial

By | December 29, 2022

Linux mv command allows us to move a file or directory to another directory. In this tutorial, we will introduce how to use this command by using some examples.


We can use linux mv command as follows:

mv [Option] source destination

Option can be:

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
mv -n prevent an existing file from being overwritten
mv -b take a backup of an existing file that will be overwritten by mv. This will create a backup file with the tilde character(~) appended to it

Then, we can use some examples to show how to use it.

Move some files

For example:

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

main.c and def.h will be moved to /home/usr/rapid/

mv *.c bak

All .c files will be moved to bak directory

Rename file or directory

mv main.c main.bak

main.c file will be renamed main.bak

mv bak bak2

bak folder will be renamed bak2

Move directory

mv bak /home/bak2

bak folder will be moved to /home/bak2