# How to use the Linux mv command to move files and directories

With the [Linux](https://www.ionos.com/digitalguide/server/know-how/linux-the-cost-effective-alternative-to-windows/ "Linux – the cost-effective alternative to Windows") mv command you can move files or even entire directories. You can even use the command to rename them, however, other commands are better suited for this purpose.

## What is the Linux mv command?

This Linux mv command has two important functions. The first is to **move files from one directory to another**. You can also use the command to move whole directories. The second allows you to rename files or folders. However, other [Linux commands](https://www.ionos.com/digitalguide/server/configuration/linux-commands-an-overview-of-terminal-commands/ "Linux commands: An overview of terminal commands") and graphic interfaces are usually better suited for this task. The mv command works in all common [Linux distributions](https://www.ionos.com/digitalguide/server/configuration/linux-distributions/ "Linux distributions") such as [Ubuntu](https://www.ionos.com/digitalguide/server/know-how/ubuntu-the-linux-system-for-everyone/ "Ubuntu: The Linux system for everyone"). Its name is derived from the word “move”.

## How does the mv command work?

When using the mv command, users request that the system moves a specific file or a complete directory from one place to another. There are **two different ways** to do this: You can either first open the source directory with the [Linux cd command](https://www.ionos.com/digitalguide/server/configuration/linux-cd-command/) and move the file from there to the target directory or you can set the source directory in the command and carry out the move from another working directory. We will show you examples of both at the end of this guide. To rename a file, you simply put the new name where you normally put the target directory.

## What does the mv syntax look like?

The syntax for Linux mv looks as follows:

```shell
$ mv [Option] [Source] [Target]
```

mv is the actual command which can be adjusted using the options. \[Source\] and \[Target\] can be both files or directories. However, it’s important that the **source is stipulated before the target**. On top of this, you also need to ensure that there are no typos otherwise the command won’t work.

## What options does the mv command have?

You have three options in mv:

- **-i or --interactive:** This option will tell the system to ask whether a file or directory should be overwritten.
- **-u or --update:** This option will only move a source if the target file is older.
- **-v or --verbose:** This option will show the progress of any move.

## Examples of a mv command

To better understand exactly how Linux mv works, here are a few examples:

```shell
$ mv customers.txt ~/Documents/Contacts/
```

This command moves the file *customers.txt* from its current directory to the new directory *~/Documents/Contacts/*.

```shell
$ mv /Home/Invoices/customers.txt /Documents/Contacts/
```

You can use this option to move the file *customers.txt* from the folder */home/invoices* to the new one */Documents/Contacts/*.

```shell
mv *.txt /Documents/
```

This moves all files with a *.txt extension* to the folder */Documents/*.

```shell
$ mv customers.txt customers_new.txt
```

This renames the file from *customers.txt* to *customers\_new.txt*.

```shell
$ mv Invoices Invoices_old
```

This renames the folder */Invoices/* in the current directory to */Invoices\_old/*.


This is a markdown version of: [https://www.ionos.com/digitalguide/server/configuration/linux-mv-command/](https://www.ionos.com/digitalguide/server/configuration/linux-mv-command/) for AI/LLM consumption.