To move files in Linux, you use the mv command. This command allows you to relocate files from one location to another or rename them.
Basic Syntax
mv [options] SOURCE DESTINATION
Examples of Moving Files
-
Moving a File to a Different Directory:
To move a file namedexample.txtto a directory calledarchive, you would use:mv example.txt /path/to/archive/ -
Renaming a File:
You can also use themvcommand to rename a file. For example, to renameexample.txttonew_example.txt:mv example.txt new_example.txt -
Moving Multiple Files:
To move multiple files at once to a directory, specify all the source files followed by the destination directory:mv file1.txt file2.txt /path/to/archive/ -
Using Wildcards:
You can use wildcards to move files that match a pattern. For example, to move all.txtfiles to thearchivedirectory:mv *.txt /path/to/archive/
Important Notes
-
If the destination directory does not exist, you will receive an error.
-
If a file with the same name exists in the destination, it will be overwritten without warning unless you use the
-ioption to prompt before overwriting:mv -i example.txt /path/to/archive/
Summary
The mv command is a versatile tool for moving and renaming files in Linux. You can move single files, multiple files, or use wildcards to select groups of files.
If you have any more questions or need further assistance, feel free to ask!
