Site icon LinuxCommands.site

mv command tutorial in linux/unix with examples and use cases

linux mv command – move (rename) files or directories.

Linux mv command is used to rename or move a file or directory to another location.

syntax

       mv [OPTION]... [-T] SOURCE DEST
       mv [OPTION]... SOURCE... DIRECTORY
       mv [OPTION]... -t DIRECTORY SOURCE...

Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

options

examples

Rename file or directory

➜ mv file.log fileNew.log


➜ mv dir newDir

Move multiple files

➜ mv access.log file.log newDir

OR

➜ mv *.log newDir

Move overwriting without asking (force)

➜ mv -f file.log newDir

Interactive mode move overwrite files and backup original files

If the target file does not exist, it will be created. If the target file exists, a warning will be prompted. Enter “Y” to back up the original file and overwrite it.

➜ mv -bi file.log newDir

OR

➜ mv -biS ~ file.log newDir

Move all files and folders in the current directory

➜ mv * /tmp

move just files

➜ find . -type f -exec mv {} /tmp \;

Exit mobile version