Command Prompt - How to Use Basic Commands

After we have shared how to open and customize Command Prompt, it is time to see how to use it to perform basic operations. This article will show how to execute commands like changing the working directory, viewing content of a directory, creating and renaming folders, copying, deleting files and folders, and how to launch any application from Command Prompt. Also, it will show how to get help when using the tool.

How to Navigate Between Folders

The first command from the list is CD (Change Directory). This command enables you to change the current directory (or folder).

The command CD\ takes you to the top of the directory tree.
Let's see how it works. After you open the Command Prompt, type cd\ and press Enter. You will see that it takes you to the top of the directory tree (in this case to the 'C:' drive).

NOTE: Command Prompt is not case sensitive, meaning that commands can be typed with capital letters, lowercase or a combination of them(so cd, CD or Cd will all work in the same way).

Command Prompt

Now you are working on the 'C:' drive. If you need to go to a specific folder from this drive just type CD DIRECTORYNAME. The subdirectory names are separated by \. For example when you need to access the System32 folder that is located on 'C:\Windows' just type cd windows\system32\, as shown below, and then press Enter.

Command Prompt

When you need to go to one folder up, use the cd.. command. Let's assume that you want to go back to the Windows folder. Type cd.. and press Enter. You will notice that your current directory has changed to 'C:\Windows'.

Command Prompt

How to Access a Certain Drive

To access another drive just type the drive letter followed by ':'. For example, we wanted to change the drive from 'C:' to 'D:'. We have typed d: and then pressed Enter.

Command Prompt

To change the drive and the directory at the same time, use the cd command followed by the/d switch. The parameter is used to change the current drive to a specific folder from other partition. For example, now you are on the 'D:' drive and you want to go back to the 'C:'drive directly to the Windows folder. Type cd/d C:\Windows and press Enter, as you can see in the following image.

Command Prompt

Note: By typing the drive letter you automatically move to your most recent location in that drive. For example if you are on 'd:' drive and type cd c:\windows nothing happen. But, if you type 'c:' then the working will change to c:\windows (assuming that it was the last directory you worked with on c: drive).

How to View the Content of a Folder

You can view the content of a folder by using a simple command called DIR. To test, we've created on the 'd:' drive a folder named 7tutorials with several files and subfolders.

Command Prompt

Last time the working directory was 'c:\Windows'. We will go to the folder mentioned above by using the command cd/d d:\7tutorials. To view the content of the folder we will type DIRand press Enter. A list of the files and folders contained by it is displayed, together with some details about these files and folders (size, the date and time of the last modification).

Command Prompt

How to Create a New Folder

You can make a new directory using the MKDIR (Make Directory) command. The syntax of this command is MKDIR directory name.

Let's say we need to create a new folder called 7tutorials_v1 that will be placed in the'd:\7tutorials' folder. We will type mkdir 7tutorials_v1 and then we press Enter, as shown below.

Command Prompt

To test if it worked, we will use again the dir command. The newly created folder appears in the list.

Command Prompt

Note: Don't forget that all these commands depend on the current location in the Command Prompt. So if you are at 'C:' and type MKDIR test, a new folder will be created in the 'C:'drive.

Another way to create a directory, that doesn't involve being on the desired folder, is to type the complete the path of the folder. For example, you are working on the 'D:' drive and you want to create a new folder on 'C:' drive called other_stuff. Just type mkdir c:\other_stuff and then press Enter.

Command Prompt

When you need to create a folder with subfolders at the same time you can use the MKDIR foldername\subfolder command . For instance, if we type mkdir 7tutorials_tests\beta\test1three folders will be created: 7tutorials_tests, beta, test1, in a tree-like structure.

Command Prompt

How to Rename Files and Folders

To rename files and folders you need to use the REN (Rename) command.

For folders just type ren foldername newname. For example if we want to rename the7tutorials_v1 folder to 7tutorials_final we type ren 7tutorials_v1 7tutorials_final and then pressEnter.

Command Prompt

To rename a file, use the same command, like this: ren filename.extension newname.extension. For example, to rename the 7tutorials_picture.jpg file to picture1.jpg we have to use the ren 7tutorials_picture.jpg picture1.jpg command.

Command Prompt

Copy Files and Folders

The Copy command allows you to copy files from one location to another. To use this command you have to type copy location\filename.extension location\newname.extension.

For example, let's use this command to copy the picture1.jpg file from the 7tutorials folder located on 'd:' drive to the 'd:\7tutorials\7tutorials_tests\ folder. To make things more interesting we want the file to be named testing_picture1.gif. We will write the command copy d:\7tutorials\picture1.jpg d:\7tutorials\7tutorials_tests\testing_picture1.giffollowed by Enter. You will receive a confirmation of the operation, as you can see below.

Command Prompt

If you are copying within the same directory you don't have to put the path in command. As an example, we need to copy Notes.txt from 'd:\7tutorials' in the same folder, only under a different extension, let's say Notes.doc. We will just type the command copy Notes.txt Notes.doc.

Command Prompt

To copy a folder and its content from a location to another we will use the XCOPY command followed by the /s / i operators. Let's assume that we need to copy a folder from'd:\7tutorials' to c:\backup_7tutorials. We have to type the xcopy /s /i d:\7tutorials c:\backup_7tutorials command and then press Enter. The '/s' parameter will ensure that all the directories and subdirectories will be copied, except the ones that are empty. The '/i'parameter will create a new directory if the destination folder doesn't exist and you copy multiple files.

Command Prompt

Delete Files and Folders

The DEL (Delete) is used to delete files within the directories you've created.

To delete all the files from a directory you have to type del directory name. Let's try this command. For example, from the directory 7tutorials located on the d: drive, we will delete all files from the 7tutorials_tests folder by typing the commanddel 7tutorials_tests. You need to confirm the delete process by typing the letter y and then press Enter.

NOTE: To delete hidden files you have to use /h parameter.

Command Prompt

If we need to delete a single file we will use the DEL command folowed by the filename. We need to delete the file Notes.txt from 'd:\7tutorials'. We will type in the del Notes.txtcommand followed by Enter.

Command Prompt

Here is a list of useful DEL combinations that is worth mentioning:

  • DEL *.DOC - delete all files with the DOC extension(you can use any file extension necessary, DOC is the example I used);
  • DEL Test*.* - delete all files beginning with Test;
  • DEL *.* - delete ALL files from the current directory.

The DEL command cannot be used to delete directories, therefore we will use another command to remove any empty directory: RD (Remove Directory). Previously we've deleted all the files from the 7tutorials_tests folder. It's time to delete it by typing RD 7tutorials_tests.

Command Prompt

Launch an Application from Command Prompt

To run a program from the Command Prompt, you need only to navigate to the directory that contains the executable and simply type in the program name. For example, if we want to launch Paint using Command Line, we have to go to C:\Windows\System32 and there we will find the executable called mspaint.exe. Let's see how this operation can be done, if we are onD:\7tutorials. First off all we have to change the working directory to the application's folder by typing cd/d c:\windows\System32\. Then we just write mspaint.exe and press Enter. Both commands can be seen in the capture below.

Command Prompt

How to Use Help in Command Prompt

To access help in Command Prompt you just have to type the help command and then pressEnter. A list off all available commands will be displayed, as you can see below.

Command Prompt

If a certain command interests you type help followed by the name of the command. Another way to do the same thing is to type command_name followed by the /? parameter. To test, use help cd or cd/? to display information about the cd command. In the picture below you can view the result.

Command Prompt

Conclusion

The Command Prompt remains a very powerful tool for any computer user who is willing to get his hands dirty and learn a bit. We hope this article was useful in helping you learning the basics about running commands in the Command Prompt. If you have any questions about it, don't hesitate to leave a comment.


+ Recent posts