mv Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

The 'mv' command is a Linux command-line utility used to move or rename files and directories. It can be used to move a file or directory from one location to another, rename a file or directory, or both move and rename a file or directory simultaneously. This article will explain the syntax, options, and usage of the 'mv' command in Linux.

Linux mv Command Syntax

The syntax for the mv command is as follows:

Where:

  • OPTIONS: The 'mv' command has several options that can be used to modify its behavior.
  • source and destination: The 'source' and 'destination' parameters can be either a file or a directory. If 'destination' is a directory, the source file or directory is moved to that directory. If 'destination' is a new filename, the source file is renamed to that name.

mv Command Options:

  • -v or --verbose: Displays a message for each file or directory that is moved or renamed.
  • -i or --interactive: Asks for confirmation before overwriting an existing file.
  • -n or --no-clobber: Prevents overwriting an existing file.
  • -u or --update: Moves only those files that are newer than the existing files in the destination directory.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Example Usages

  • Move a file to a new location:

    Explanation: This command will move the 'file.txt' file to the '/home/user/Documents/' directory. If a file with the same name already exists in the destination directory, it will be overwritten without any warning.

  • Rename a file:

    Explanation: This command will rename the 'oldname.txt' file to 'newname.txt' in the same directory. If a file with the same name already exists in the directory, it will be overwritten without any warning.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Tips

  • Be careful when using the 'mv' command to avoid accidentally overwriting or deleting files.

  • Use the '-v' option to get a confirmation message for each file or directory that is moved or renamed.

  • Use the '-i' option to ask for confirmation before overwriting an existing file.

  • Use the '-n' option to prevent overwriting an existing file.

  • Use the '-u' option to move only those files that are newer than the existing files in the destination directory.

Advanced Use Cases of mv Command in Linux

  • Move multiple files to a new location:

    Explanation: This command will move the 'file1.txt', 'file2.txt', and 'file3.txt' files to the '/home/user/Documents/' directory.

  • Move all files with a certain extension to a new location:

    Explanation: This command will move all files with a '.txt' extension to the '/home/user/Documents/' directory.

  • Move a directory and all its contents to a new location:

    Explanation: This command will move the 'directory1' directory and all its contents to the '/home/user/Documents/' directory.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • The 'mv' command in Linux is a powerful tool for moving and renaming files and directories.

  • The 'source' and 'destination' parameters can be either a file or a directory.

  • Use the '-v' option to get a confirmation message for each file or directory that is moved or renamed.

  • Be careful when using the 'mv' command to avoid accidentally overwriting or deleting files.