AMZ DIGICOM

Digital Communication

AMZ DIGICOM

Digital Communication

Linux mv command: move directories and files

PARTAGEZ

The mv command for Linux allows you to move entire files or directories. This command can also be used to rename files, although other commands are more suitable for this task.

Linux mv command: what is it?

The Linux mv command provides two important functions. First, you can use it to move files from one directory to another. Similarly, it can also be used to move directories. Secondly, the command allows you to rename files, or even folders. Generally speaking, however, other Linux commands or a GUI are more suitable for such tasks. The mv command works with all major Linux distributions, for example Ubuntu. The name of this command is a contraction of the English verb “move”.

How does the mv command work?

With the Linux mv command, users can instruct the system to move a specific file or an entire directory from one location to another directly from the command line. Two different possibilities available to them: start by calling the home directory using the Linux cd command, then move the file concerned from it to a target directory, or save the home directory directly in the command before performing the transfer from another working directory. Both methods are illustrated with examples at the end of this article. To rename a file, you must use the name you want to give it as the destination.

What does the mv command syntax look like?

The Linux mv command syntax is as follows:

$ mv [Option] [Fichier d’origine] [Fichier de destination]

shell

The mv command itself is refined here using options.  » [Fichier d’origine]  » And  » [Fichier de destination] can be either files or directories. However, it is essential to always indicate the origin first, then the destination. Care should also be taken to ensure that the spelling is correct, otherwise the command will not be able to execute correctly.

What are the mv command options?

For this command, there are the following three options:

  • -i or –interactive: it ensures that the system « asks » whether or not a file or directory should be overwritten.
  • -u or –update: it ensures that an original file is only moved if the destination file is older.
  • -v or –verbose: it is used to display the progress status of the move.

mv command: examples

Below are some simple examples to help you better understand exactly how the Linux mv command works.

$ mv client.txt ~/Documents/Contacts/

shell

This command moves the file client.txt from the current working directory to the directory ~/Documents/Contacts/.

$ mv /Bureau/Factures/client.txt /Documents/Contacts/

shell

This command moves the file client.txt from folder /Desktop/Invoices to folder /Documents/Contacts/.

mv *.txt /Documents/

shell

This command moves all files ending in .txt to the file /Documents/.

$ mv client.txt nouveau_client.txt

shell

This command renames the file client.txt in new_customer.txt.

$ mv Factures anciennes_factures

shell

This command renames the folder /Invoices/ from the current working directory in /old_invoices/.

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact