move cmd command - GeeksforGeeks (2024)

Last Updated : 20 Oct, 2020

Improve

The move is an internal command found in the Windows Command Interpreter (cmd) that is used to move files and folders/directories. The command is robust than a regular move operation, as it allows for pattern matching via the inclusion of Wildcards in the source path.

The command is a very generic one and is available (in one form or the other) in almost every single operating system out there (under different aliases). In this article, we will learn about the move command and would learn various uses/applications of it.

Description of the Command :

MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2 
  • [drive:][path]filename1 –
    Specifies the location and name of the file or files you want to move.
  • destination –
    Specifies the new location of the file. The destination can consist of a drive letter and colon, a directory name, or a combination. If you are moving only one file, you can also include a filename if you want to rename the file when you move it.
  • [drive:][path]dirname1 –
    Specifies the directory you want to rename.
  • dirname2 –
    Specifies the new name of the directory.
  • /Y –
    Suppresses prompting to confirm you want to overwrite an existing destination file.
  • /Y –
    Causes prompting to confirm you want to overwrite an existing destination file.

The switch /Y may be present in the COPYCMD environment variable. This may be overridden with /-Y on the command line. The default is to prompt on overwrites unless the MOVE command is being executed from within a batch script. The above output can be obtained by executing the command move /? in cmd.

The above text is a little cryptic at first, but the command is really basic and follows the minimal blueprint.

Syntax :

MOVE [options] (Source) (Target) 

Key :

  • [option] –
    An optional flag denoted by /Y or /-Y, that is used to suppress the confirmation prompt on overwritten files. The default is to prompt on overwrites unless the MOVE command is being executed from within a batch script.
  • (Source) –
    A path of the file/files that would be used to move them. This path can contain wildcards ( * ? ) in the path. If more then files are made to move, then wildcards are used.
  • (Target) –
    A path for the new location of the file.


Using the Command :
Throughout this section, we would take the following directory as example for demonstrating the usage of move command.

move cmd command - GeeksforGeeks (1)


Moving a File from One Folder to Another :

move source_path destination_path
  • source_path –
    It is the path of the file which we are willing to move, and the destination_path is the location to which we want the file to be moved.

Example :

move cmd command - GeeksforGeeks (2)

  • The Dir /b command is used to list all the files and folders inside a directory.
  • In the above example, we have moved an extension-less file named salute from C:\suga to C:\suga\apples directory.

Moving Multiple Files from One Path to Another :

move source_path destination_path
  • source_path –
    It is a path containing wildcards that will allow more than one file to be taken as a source. The destination_path is now a path to a directory where the moved files would reside (should not contain wildcards).

Example :

move cmd command - GeeksforGeeks (3)

See Also
xcopy

  • In the above example we have moved all the files inside C:\suga folder which matches the pattern *.* to C:\suga\Apples directory.
  • It should be noted that wildcard in source_path should match with the file(s) otherwise it would result in source_path being null, and a subsequent error.


Moving Directory from One Path to Another :

move source_dir_path Destination_dir_path
  • source_dir_path –
    It is the path to the directory to which we are moving, and destination_dir_path is the new location where it would be moved to.

Example :

move cmd command - GeeksforGeeks (4)

  • In the above example, we have moved the C:\suga\apples directory to C:\Users\Public directory.
  • Multiple Directories can be moved using the method described in Moving multiple files from one path to another (with little modification to make is eligible for directories).


Moving a File to Another Folder with a Same Name File already existing :

There are two ways to tackle this situation –

  1. Abort the move process.
  2. Continue the move process, by overwriting the existing file with the newer one.

By default, the move command upon encountering any name collisions would prompt the user, asking whether he wants to rewrite the existing file with the new one, or stop the move process (via a Y/N prompt). To abort the move process, the user can simply enter N in the prompt input, stating that the file should not be overwritten. The prompt seeking for user input (for overwrite of files) appears as follows –

Overwrite {full_file_path}? (Yes/No/All): 

When the users enter N in the prompt the output appears as follows –

Overwrite {full_file_path}? (Yes/No/All): N0 file(s) moved.

When the user enters Y in the prompt the output appears as follows –

Overwrite {full_file_path}? (Yes/No/All): Y1 file(s) moved.

To continue the move process by overwriting existing files (on all name collisions), a /Y switch needs to be added to the command as follows –

move /Y source_path destination_path 

Like Article

Suggest improvement

Next

cmd | Dir command

Share your thoughts in the comments

Please Login to comment...

move cmd command - GeeksforGeeks (2024)

FAQs

How to use move command in cmd? ›

move cmd command
  1. [drive:][path]filename1 – Specifies the location and name of the file or files you want to move.
  2. destination – Specifies the new location of the file. ...
  3. [drive:][path]dirname1 – Specifies the directory you want to rename.
  4. dirname2 – Specifies the new name of the directory.
  5. /Y – ...
  6. /Y –
Oct 20, 2020

How to relocate in cmd? ›

To relocate a file to another folder, you can use the "mv" command (short for move) in the command line or terminal. The syntax for the command is as follows: mv [source file] [destination folder]

How to maximize cmd? ›

You can also press Alt + Shift + Enter when the cmd window is open.

How do I move up one level in CMD? ›

To go up one level of the directory tree, type the following: cd .. The special file name, dot dot ( .. ), refers to the directory immediately above the current directory, its parent directory.

How does move command work? ›

In computing, move is a command in various command-line interpreters (shells) such as COMMAND.COM , cmd.exe , 4DOS/4NT, and PowerShell. It is used to move one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name.

What does the move command do? ›

The mv command moves files and directories from one directory to another, or renames a file or directory. If you move a file or directory to a new directory, it retains the base file name. When you move a file, all links to other files remain intact, except when you move it to a different file system.

How to move in directory in CMD? ›

To change the directory in Command Prompt (Cmd), use the “cd” command followed by the desired directory path, e.g., “cd C:NewDirectory.” Let's show you step by step. CMD, or Command Prompt on the Windows operating system, is a functional text-based interface.

How do I move to root in CMD? ›

Type "cd.." and press "Enter" to go back one directory. Type "cd\" and press "Enter" to go to the root of the drive.

How do I move multiple files in CMD? ›

You can use the "cd" command to change directories. 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.

How to run cmd fast? ›

How can I speed up my computer using CMD? You can speed up your computer using CMD by disabling unnecessary startup programs with “msconfig,” defragmenting drives using “defrag,” and running the “sfc /scannow” command to fix system file issues.

What is the maximum for cmd? ›

The maximum length of the string that you can use at the command prompt is 8191 characters. This limitation applies to: the command line. individual environment variables that are inherited by other processes, such as the PATH variable.

How do I clean up cmd? ›

Open Command Prompt with admin privileges by typing cmd in the search box, right-click on the command prompt and click on the run as administrator. Type cleanmgr, and hit Enter. In the Drive Selection window, select the drive you want to clean up and click OK.

How do I move all files in CMD? ›

Step 1: Press Win + R to open the Run window. Step 2: Type cmd into the text box and hit Enter to open Command Prompt. Step 3: Type move [<source>] [<target>] and hit Enter. For example, I need to move files in the fortest folder from E: drive to D:\RecoveryDestination.

How to move a file in Windows CMD? ›

Move a file from one folder to another. Syntax MOVE [options] [Source] [Target] Key source : The path and filename of the file(s) to move. target : The path and filename to move file(s) to. options: /Y Suppress confirmation prompt, when overwriting files. /-Y Enable confirmation prompt, when overwriting files.

What does ./' mean in path? ›

This is where the dot slash ./ notation comes in. It means “Look in the current directory.” When you use ./, you tell Ubuntu or Fedora or SUSE or whatever Linux distribution you're using to look in the current directory for the command you wish to run, and completely ignore what's on the application PATH.

How do I use the move function in Windows? ›

Select the item you want to move by holding down the right-mouse button (or the alternate mouse button if you're using the mouse with your left hand). Drag to the destination folder and release the mouse button.

How to move file in CMD windows 10? ›

To move a file/folder simply input “move [filename] [destination]” into the prompt. The terms in brackets should be replaced with their literal substitutes.

Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 5802

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.