• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

mv Command Examples in Linux

by admin

The mv command moves files and directories to other locations. It is similar to the cp command but does not leave the initial object in place. Therefore, mv is more like a cut and paste operation. The Bash shell does not have a dedicated rename command but instead uses mv to accomplish that function. The act of “moving” a file or directory and supplying a new name as the destination essentially renames that object.

Syntax

The syntax of the mv command is:

$ mv [options] {file/directory name to move} {file/directory name destination}

For example, to move ~/file1 to /opt/file1:

$ mv ~/file1 /opt/mylist

For renaming purposes, the syntax is:

$ mv [options] {old file/ directory name} {new file/directory name}

mv Command Options

The following table lists some of the options for the mv command.

Option Description
-i Interactive mode. Ask before overwriting destination files.
-f Force the move. If a destination file exists, overwrite it unconditionally.

mv Command Examples

1. Move a file to an arbitrary location:

# mv source target

2. Move files into another directory, keeping the filenames:

# mv source1 source2 source3 target_directory

3. Do not prompt for confirmation before overwriting existing files:

# mv -f source target

4. Prompt for confirmation before overwriting existing files, regardless of file permissions:

# mv -i source target

5. Do not overwrite existing files at the target:

# mv -n source target

6. Move files in verbose mode, showing files after they are moved:

# mv -v source target

Filed Under: Linux

Some more articles you might also be interested in …

  1. a2disconf Command Examples in Linux
  2. ffuf Command Examples in Linux
  3. ulimit: command not found
  4. RedHat / CentOS : How to change currently active slave interface of bonding online
  5. Difference between the Java heap and native C heap
  6. How to view past performance with sar in Linux
  7. mycli: command not found
  8. chattr Command Examples to Change File Attributes (Make files immutable)
  9. Linux OS Service ‘anacron’
  10. Audit rules for monitoring Copy, move, delete and kill Commands In Linux

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright