EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

mv command in Linux

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » Linux Tutorial » mv command in Linux

mv command in Linux

Introduction to mv command in Linux

The mv command termed as “Move”, which is a command-line utility to move files or directories from source to target. It supports the moving of a single file, multiple files, and directories. It is very similar to copy command (cp), used for copying and remove command (rm), used for deleting. The only difference is that move command has features of both commands for renaming and moving of files.

Prerequistive

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

To run move command (mv), to move a file or directory we must need to have to write permission on the source and destination else we will receive an error of permission denied.

Syntax

mv [OPTION] SRC DEST

where SRC is Source file or directory and DEST is Target file or directory.

Application of various factor:

  • The source can be single or more files or directories and destination can be a single file or directory.
  • When multiple files or directories are passed as a source then the destination needs to be a directory. In this scenario, the source files will move to the target directory. If we specify a single file as a source, then the destination target is an existing directory, then the file will be moved to the specified directory.
  • When we specify a single file as a source and a single file destination then we are renaming the file.
  • When our source is a directory and destination does not exist then the source will be renamed to the destination or if destination exists then it will be moved inside the destination directory.

Options

There are a variety of options available for move command.

1. mv -i: This option signifies “Interactive Mode”, means that it will prompt the user’s confirmation before moving a file that will replace/overwrite already existed file with the same name. In this scenario, we have to enter “y” to confirm or overwrite the file.

2. mv -n: This option used as no-clobber which implied that it will prevent a file from overwriting. In simple terms, we can rename a file to match another file and still keep the content of the already existing file.

Popular Course in this category
Linux Training Program (16 Courses, 3+ Projects)16 Online Courses | 3 Hands-on Projects | 160+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (6,021 ratings)
Course Price

View Course

Related Courses
Kali Linux Training (3 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

3. mv -v: It means moving the file in “verbose mode”, means it will display the activity status happening while mv command is running.

4. mv -u: This option implies as “update mode”, means it will update the destination file is missing only when the source file has any new content or even when the destination file is missing.

5. mv *: This option will move multiple files to a specific/current directory.

6. mv –suffix=suffix: This option is used to take a backup of the files or directories before overwriting it. Default is “~”.

7. mv –version: This option checks the version of mv command.

8. mv -f, –force: This option will move the files or directories without any prompt. This option will be useful if we need to overwrite multiple sets of files whose permission is read-only and if you do not specify this option then prompt will appear for every file.

Examples of mv command in Linux

Given below are the examples of mv command in Linux:

Example #1 – Rename the File.

When the file is renamed with mv command then the inode number remains the same even after moving it to a different file name. Indone number changes when moving and changing filesystem

Command: mv File.txt File1.txt

Output:

mv command in Linux 1

Note: ls -i will display the inode number of a file.

Example #2 – Renaming the Directory.

Similarily like renaming of a file, we can also rename a directory by mv command. Here also inode number is the same as in renaming a file.

ls -l will display the files and directory in the directory. For displaying the only directory, make use of -d option. -i option which will display the inode number of the directory.

Command: mv Dir1 Dir2

Output:

mv command in linux 2

Example #3 – Prompting of Terminal for confirmation of overwrite.

mv command will not ask confirmation while overwriting but default if in the same place. It will simply overwrite it. To avoid any issue, we want a confirmation from the mv command before overwriting the destination file so, we need the “-i” option as shown. Then we can type Y or N for the operation to take place.

Command: mv -i File.txt File1.txt

Output:

mv command in Linux 3

When destination files permission is different than the source file then mv -i command will display the below confirmation.

Output:

prompting of terminal 3.1

Example #4 – Moving Multiple File to a Specific Directory.

We can move multiple files or dir with MV command. Below will show how to move the content of dir using MV command.

Command:mv * app1/

Output:

movie multipe file to specific directory

Example #5 – Backup file creation before overwriting.

Now when we use mv –suffix, a backup file would be created. Now that previous file will be moved with new suffix specified within -S of –suffix option.

Command :mv --suffix=.bak File1 File2

Output:

backup file creation before overwriting

Note: mv –suffix can be written as an alias which would backup the same as mv command automatically.

Example #6 – File movement in the destination path that does not exist.

mv * will help in the movement of all files to a new location. mv -u command will help in moving files or dir to the new location which were not existing and not updated/changed as well.

The below command will move only the File2 and File2 from app to app1, as the File1 file already present in app1, so it will move.

Command: mv -u app/* app1/

Output:

file movement in the destination

Recommended Articles

This has been a guide to mv command in Linux. Here we discuss the basic concept, options, and examples of mv command in Linux. You may also have a look at the following articles to learn more –

  1. Unix Shell Commands
  2. Types of Shells in Linux
  3. Ubuntu Command
  4. rmdir command in Linux

Linux Training Program (16 Courses, 3+ Projects)

16 Online Courses

3 Hands-on Projects

160+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • GREP Command in Linux
    • Linux Curl Command
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Find Directory Linux
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux Cal Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Linux Format
    • Cheat Sheet Linux
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Uses
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
    • Kali Linux root password
    • Kali Linux Alternative
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Linux Training Program (16 Courses, 3+ Projects) Learn More