How to move files?

QuestionsQuestions8 SkillsProBasic Files OperationsAug, 05 2025
0169

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

  1. Moving a File to a Different Directory:
    To move a file named example.txt to a directory called archive, you would use:

    mv example.txt /path/to/archive/
  2. Renaming a File:
    You can also use the mv command to rename a file. For example, to rename example.txt to new_example.txt:

    mv example.txt new_example.txt
  3. 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/
  4. Using Wildcards:
    You can use wildcards to move files that match a pattern. For example, to move all .txt files to the archive directory:

    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 -i option 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!

0 Comments

no data
Be the first to share your comment!