mv command in Linux/Unix

mv command is an application used to move files and directories in a Unix environment.

mv command syntax

$ mv [optionssource dest


Also can be seen using manual command:

$ man mv
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 two files test1.txt secondfile.txt files to /home/designcoder/ directory:

$ mv test1.txt secondfile.txt /home/designcoder/

Move all TXT files in current directory to subdirectory backup :

$ mv *.txt backup

Move all files in subdirectory backup to current directory :

$ mv backup/* .

Rename file test1.txt to main.bak:

$ mv test1.txt hello.bak

Rename directory backup to backuptest:

$ mv backup backkuptest

Update – move when test1,txt is newer:

$ mv -u test1.txt backup

Move main.c and prompt before overwrite backup/test1.txt:

$ mv -v test1.txt backup
'test1.txt' -> 'backup/test1.txt'

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>