Home » Unix command and scripts » How to move a file/directory in Linux with Example

How to move a file/directory in Linux with Example

We can move file or directory from one location to another location in Linux using mv command . This command can also be used to rename the file or directory also.This is a quite a useful command.

mv – move files(s) /dirs

Options: –
-f   mv will move the file(s) without prompting even if it is writing over an existing target.

-i   mv will prompt for confirmation whenever the  move would  overwrite  an  existing  target

-b mv will take backup before overwriting

-n mv will not overwrite the file if it exists

Examples

moves f1.txt to f2.txt, if f2.txt exists prompts for confirmation
mv –i f1.txt f2.txt

moves f1.txt to f2.txt, if f2.txt exists ,it just overwrite without prompting
mv –f f1.txt f2.txt

moves f1.txt to f2.txt, if f2.txt exists ,then backup is taken
mv -b f1.txt f2.txt

moves f1.txt to f2.txt, if f2.txt exists ,then backup is taken with suffix .bak
mv -b --suffix=.bak f1.txt f2.txt

moves f1.txt to f2.txt, if f2.txt exists ,move does not happen
mv -n f1.txt f2.txt

move file1 to dest directory
mv file1 dest

moves file1 to 3 to dst_directory
mv file1 file2 file3 dest_directory

moves directory app and all its subdirectories files to /u000 directory
mv app /u000

moves f1.txt to f2.txt in the directory oracle
mv f1.txt oracle/f2.txt
linux mv command

You can get all the option of linux mv command using command

man mv
linux mv command

Hope you like explanation on Linux mv command. Please do provide the feedback so that it can improved

Also Reads

grep command in Linux : Grep command Means – globally search regular expression.grep command in unix is used for searching text,regular expression across multiple files
awk command in unix with examples :Awk command in Unix or Linux is a powerful command for processing text. Learn about awk syntax, records, fields, line Separator with examples of awk in unix
sed command in unix examples : sed command is a Stream Editor – works as a filter processing  input line by line And here are 32 Useful sed command examples in Linux/Unix
tee command in Unix : Check out about tee command in Unix,what options are available, how to append file using tee command, how to write to multiple files
RSYNC Command : RSYNC command – sync the data between two directory
https://en.wikipedia.org/wiki/Linux

See also  RSYNC command – sync the data between two directories

Leave a Comment

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

Scroll to Top