Skip to content

Windows Command Line Basics

Introduction

The Windows Command Line (Command Prompt, CMD) is a powerful tool that allows users to interact with the system using text-based commands. It provides greater control, automation capabilities, and flexibility compared to graphical user interfaces (GUIs). This tutorial covers essential Windows commands to help you efficiently navigate and manage the command line.


Pay Attention to Path Formatting!

Windows does not differentiate between uppercase and lowercase letters, but it uses backslashes (\) instead of / for paths.

Display the Current Directory

To check your current working directory, use:

cd # (1)
  1. Displays the current working directory.
Example Output
C:\Users\User> cd
C:\Users\User

Changing Directories

  • Navigate to a specific directory:
cd \Path\to\Folder # (1)
  1. Moves to the specified directory.

  2. Move up one level:

cd .. # (1)
  1. Moves up one directory level.

  2. Return to the user directory:

cd %USERPROFILE% # (1)
  1. Returns to the user’s home directory.

Absolute vs. Relative Paths!

  • Relative Paths: cd Documents changes the directory relative to the current location.
  • Absolute Paths: cd C:\Windows always goes to the same location, regardless of your current directory.

Managing Files and Folders

Creating Files

  • Create an empty file:
echo. > file.txt # (1)
  1. Creates a new empty file.

  2. Create a file with content:

echo "Hello World" > file.txt # (1)
  1. Creates a new file and writes "Hello World" into it.

Viewing Files

  • Display the contents of a file:
type file.txt # (1)
  1. Displays the content of the specified file.

Creating Folders

mkdir MyFolder # (1)
  1. Creates a new folder with the specified name.

  2. Create multiple nested directories at once:

mkdir Folder1\Subfolder2\Subfolder3 # (1)
  1. Creates a hierarchical directory structure in one command.

Listing Directory Contents

  • Display all files and folders in the current directory:
dir # (1)
  1. Lists the contents of the current directory.

Moving and Renaming Files and Folders

  • Move a file:
move file.txt MyFolder\ # (1)
  1. Moves the file to the specified folder.

  2. Rename a file:

rename old_file.txt new_file.txt # (1)
  1. Renames the file.

  2. Move a folder and its contents:

move MyFolder NewFolder # (1)
  1. Moves the entire folder and its contents.

Deleting Files and Folders

  • Delete a file:
del file.txt # (1)
  1. Permanently deletes the specified file.

  2. Delete an empty folder:

rmdir MyFolder # (1)
  1. Deletes the specified folder if it is empty.

  2. Delete a folder and all its contents:

rmdir /s /q MyFolder # (1)
  1. Deletes the folder and all files within it recursively.

Retrieving System Information

  • Display the current IP address:
ipconfig # (1)
  1. Shows network and IP information.

  2. Display detailed network information:

ipconfig /all # (1)
  1. Shows a detailed list of all network interfaces and configurations.

  2. Display running processes:

tasklist # (1)
  1. Displays a list of currently running processes.

  2. Terminate a process:

taskkill /IM notepad.exe /F # (1)
  1. Forcefully ends the Notepad process.

Conclusion

The Windows Command Line is a useful tool for system management, automation, and file operations. With these fundamental commands, you can work more efficiently. A great way to develop CLI skills is by experimenting in a test environment.