Premium lesson

Moving Files & Directories

Shell·2 min read·Jan 1, 2025

In Unix-like operating systems, moving and renaming are essentially the same operation, as renaming a file or directory simply consists in moving it to a specified location in the filesystem under a different name.

Moving files and directories

To move a single file or directory into another directory, you can use the mv command — which stands for move — as follows:

$ mv source target

Where:

  • source is the path to the file or directory you want to move.

  • target is the path to the directory you want to move it into.

Note: When moving a directory into another directory, all its content including its subdirectories will be moved with it.

Example

Let's consider this directory:

icon light bulb key

Unlock the CLI & Scripting with Bash module

Learn how to gain advanced control over the OS and automate complex routine tasks prone to manual errors with the CLI and Bash scripting.

You get immediate access to:

  • 34 focused lessons across the CLI and Bash
  • 4 real-world projects with commented solutions
  • Ongoing updates to this bundle
  • Lifetime access to this bundle
Unlock this module