Basic Windows Console Commands

Terminal or console commands are always important if you want to take your web designing or developing skills to advanced level. Whether you are using a SASS for designing, Git for version control, or Composer for a PHP project in Laravel, you just cannot bypass these console commands if you want to work efficiently. If you are using Windows and are new to terminal commands, this post is for you. The basic console that comes with Windows is the good old Command Prompt (cmd.exe) and in this post, we’ll go through the basic commands for Command Prompt.
 
For easier referencing, this post is divided in 4 sections based on the types of commands:

  1. Navigation
  2. Adding, Renaming
  3. Deleting
  4. Copying, Moving

 
 

Go to the root of current drive

cd\

 

Change current folder

cd followed by the folder name. For example, here is the command to go to Windows folder from the C drive root:

cd Windows

Sub-folder names must be separated by a backslash. For example, here is the command to go to System32 folder from the C drive root:

cd Windows\System32

 

Go up one folder

cd..

 

Access a certain drive

Drive letter followed by a colon. For example, here is the command to go to D drive root:

D:

 

Change current drive and folder with a single command

cd followed by /d, followed by full path address of the folder. For example, here is the command to go to C drive’s System32 folder from any other drive or a folder inside any other drive:

cd /d C:\Windows\System32

 

View contents of current folder

dir

 

Open a file or run an application in the current folder

Just type in the file or application name followed it’s extension and press Enter. For instance, here is the command to open a Word document new_tasks.docx in the current folder:

new_tasks.docx

 
 

Adding, Renaming

Add new folder in current location

mkdir (make directory) followed by the new folder name. For example, here is the command to create a new folder called My_Notes inside the current folder:

mkdir My_Notes

md command also works life mkdir. For example, the previous command can also be written as

md My_Notes

 

Add new folder in any location

mkdir followed by the full path of the new folder. For example, here is the command to create a new folder called My_Notes inside D drive while working in another folder:

mkdir D:\My_Notes

 

Add new folder and sub-folder in current location with a single command

mkdir followed by folder name and sub-folder name separated by a backslash. For example, here is the command to create a new folder called My_Notes containing another new folder called Important_Notes in current location:

mkdir My_Notes\Important_Notes

 

Rename folder in current location

ren followed by folder name and new folder name separated by a space. For example, here is the command to rename My_Notes folder to My_Recent_Notes in current location:

ren My_Notes My_Recent_Notes

 

Rename file in current location

ren file_name.extension new_file_name.extension. For example, here is the command to rename featured_image.png file to featured_image_final.png in current location:

ren featured_image.png featured_image_final.png

 
 

Deleting

Delete file in current location

del file_name.extension. For example, here is the command to delete featured_image.png file in current location:

del featured_image.png

 

Using wildcard (*) for delete

You can use wildcard (*) to delete multiple files. For example, to delete all files in the current folder with .png extension:

del *.png

Or to delete all files in current folder staring with featured:

del featured*.*

Or to delete all files in current folder:

del *.*

 

Delete an empty folder

rd (remove directory) followed by folder name inside the parent folder. For example, to delete an empty folder My_Notes, go to it’s parent folder and use the following command:

rd My_Notes

 
 

Copying, Moving

Copy a file

copy location\file_name.extension new_location\new_file_name.extension. For example, here is the command to copy New_Note.txt file inside D:My_Notes folder to D:\Revision folder with a new name New_Note_v1 and a new extension .doc:

copy D:\My_Notes\New_Note.txt D:\Revision\New_Note_v1.doc

If you want to copy the file in the same folder, then you can just go to the folder and use copy command without the location part.
 

Copy contents of a folder

xcopy /s /i location\folder_name location\new_folder_name For example, to copy the contents of a folder My_Notes inside D drive to a folder My_Notes_Backup in E drive use the following command:

xcopy /s /i D:\My_Notes E:\My_Notes_Backup

The /s parameter will ensure that all the non-empty folders and non-empty sub-folders inside the selected folder will also be copied.
The /i parameter will create the new folder in the destination if it doesn’t exist.
 

Move a file

move location\file_name.extension new_location\new_file_name.extension. For example, here is the command to move New_Note.txt file inside D:\My_Notes folder to D:\Revision folder with a new name New_Note_v1 and a new extension .doc:

move D:\My_Notes\New_Note.txt D:\Revision\New_Note_v1.doc

 
 
These are the basic commands you’re going to need. Hope this post helps!

Advertisements

One thought on “Basic Windows Console Commands

Ask a question or leave a reply!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s