Move files in the Linux terminal (2024)

Use the mv command to move a file from one location to another.

Move files in the Linux terminal (1)

Image by:

CC BY-SA Seth Kenlon

To move a file on a computer with a graphical interface, you open the folder where the file is currently located, and then open another window to the folder you want to move the file into. Finally, you drag and drop the file from one to the other.

To move a file in a terminal, you use the mv command to move a file from one location to another.

$ mv example.txt ~/Documents$ ls ~/Documentsexample.txt

In this example, you've moved example.txt from its current folder into the Documents folder.

As long as you know where you want to take a file from and where you want to move it to, you can send files from any location to any location, no matter where you are. This can be a serious time saver compared to navigating through all the folders on your computer in a series of windows just to locate a file, and then opening a new window to where you want that file to go, and then dragging that file.

The mv command by default does exactly as it's told: it moves a file from one location to another. Should a file with the same name already exist in the destination location, it gets overwritten. To prevent a file from being overwritten without warning, use the --interactive (or -i for short) option:

$ mv -i example.txt ~/Documentsmv: overwrite '/home/tux/Documents/example.txt'? 

What to read next

Move files in the Linux terminal (5)

Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time.

2 Comments

These comments are closed.

Move files in the Linux terminal (9)This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.

Move files in the Linux terminal (2024)

FAQs

How do you move a file in Linux terminal? ›

To move a file, type mv followed by the file you want to move and its destination as shown in the figure below. mv can also be used to rename a file, to do this, use mv followed by the current filename and its new name as shown below.

How do you move all files in a file in Linux? ›

Simply use mv folder1/folder2/* <destination> . This command will move all files in folder1/folder2 to your specified destination.

How do I move too many files in Linux? ›

To move multiple files or directories in Linux, you need to specify all the SOURCE files or directories and the DESTINATION directory where they will be moved to. It's important to note that when moving multiple files or directories, the DESTINATION must be a directory, not a file.

How do I move a specific number of files in Linux? ›

Let's break this down:
  1. source_directory=”./” – defines the location of the files to move (which is the current directory in this example)
  2. destination_directory=”../destination” – defines where to move the files to.
  3. num_files=5 – sets 5 as the number of files to move.
Mar 16, 2024

How do I move a file in Linux example? ›

For Example:

If we have a file “name = geeksforgeeks” and want to move it to location “name = /home/jayeshkumar/jkj”. Here we used the `ls` command to see the files and directories in the following location. This command moved file “name = `geeksforgeeks`” to the destination “name = “/home. jayeshkumar/jkj/”.

How to move files in command line? ›

To relocate or move a file to another folder, you can use the following commands based on the operating system you are using: For Windows Command Prompt: To move a file to another folder in Windows Command Prompt, you can use the move command. Here's the syntax: move "source\filename" "destination\folder\filename"

How do I move a complete folder in Linux? ›

Right-click on the directory and choose the "Cut" or "Move" option from the context menu and navigate to the destination directory where you want to move the selected directory. Step - 3: Right-click on the destination directory and choose the "Paste" or "Move Here" option from the context menu.

How do I move all files in a folder in command prompt? ›

For example, if the folder is located on the C drive, you would type "cd C:\folder_name" and press Enter. Use the command "move /y" followed by the path of the source folder and the destination folder. For example, to move all files in the "C:\source_folder" and i.

What is chmod 777 command? ›

The `chmod 777` command is used in Unix-based systems (such as Linux or macOS) to change the permissions of a file or directory.

How do I move a lot of files at once? ›

Windows: You can select multiple files by holding down the "Ctrl" key while clicking on each file, then right-click on one of the selected files and choose "Cut." Then, navigate to the folder you want to move the files to and right-click in an empty space, then choose "Paste."

Is mv faster than rsync? ›

Assuming it works perfectly the first time, then a cp / mv is likely to be of comparable speed to rsync. If it's any faster it would be only by a trivial margin.

How do I move all files except few in Linux? ›

The first is -maxdepth 1 which prohibits reiteration to other folders. The second is -mindepth 1 which prevents the source folder from being included in the results to be transferred. The third option is the -not -name unwanted_filename option that uses the unwanted filename as an index to list the remaining content.

How to copy 100 files in Linux? ›

To copy multiple files into the same directory in Linux, you can use the "cp" command followed by the names of the files you want to copy, separated by a space, and then the destination directory. For example, if you want to copy files named "file1. txt", "file2. txt", and "file3.

How do I move and replace a file in Linux? ›

-i (Interactive): -i option makes the command ask the user for confirmation before moving a file that would overwrite an existing file, you have to press y for confirm moving, any other key leaves the file as it is. This option doesn't work if the file doesn't exist, it simply rename it or move it to new location.

How do I copy multiple files to one location in Linux? ›

To copy multiple files, you can use the command: cp file1 file2 file3 destination_directory. Q. How do I copy a directory recursively in Linux? To copy a directory and all its contents recursively, you can use the command: cp -r source_directory destination_directory.

How do I drag a file into terminal? ›

Enter the path of a file or folder: Drag the file or folder to the Terminal window. The item's absolute path appears on the command line. You can also drag a folder from the title bar of a Finder window. Run an executable file: Drag the file to the Terminal window, then press Return.

How do I move an executable file in Linux? ›

Just copy it to a thumb drive or over the network like any other file. There aren't a *lot* of these (well, there are, but we're usually talking utilities.) Other applications will have a host of other files that that .exe file needs, but will still let you just move the folder they're in, like any other file.

How do you move files inside a folder in Linux? ›

Using mv Command

The mv command is used to move files and directories from one place to another. We can also use it to rename files and directories. This will move all the files from /path/subfolder to /path/ except for hidden files and directories.

Top Articles
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 6009

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.