> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/internal-and-external-network-sec/privilege-escalation/windows/essential-commands.md).

# Essential Commands

### `cd` – Change Directory

Used to navigate between directories or switch drives.

**Syntax:**

```cmd
cd [<directory>]
```

**Examples:**

* Change to Desktop folder

  ```cmd
  cd Desktop
  ```
* Show current directory

  ```cmd
  cd
  ```
* Show help

  ```cmd
  cd /?
  ```
* Switch to `D:` drive

  ```cmd
  d:
  ```

***

### `dir` – List Files and Directories

Displays the contents of a directory.

**Syntax:**

```cmd
dir [<path>] [<options>]
```

**Examples:**

* Basic listing

  ```cmd
  dir
  ```
* Show help

  ```cmd
  dir /?
  ```
* List hidden files

  ```cmd
  dir /aH
  ```
* List directories only

  ```cmd
  dir /aD
  ```
* List system files

  ```cmd
  dir /aS
  ```
* List read-only files

  ```cmd
  dir /aR
  ```
* Show 8.3 short names

  ```cmd
  dir /x
  ```
* Bare format (for scripting)

  ```cmd
  dir /b
  ```

***

### `mkdir` – Make Directory

Creates one or more directories.

**Syntax:**

```cmd
mkdir <directory_name>
```

**Examples:**

* Create single directory

  ```cmd
  mkdir dir1
  ```
* Create nested directories

  ```cmd
  mkdir dir1\dir2
  ```
* Show help

  ```cmd
  mkdir /?
  ```

***

### `set` – Environment Variables

Displays or sets environment variables.

**Syntax:**

```cmd
set [<variable>[=<value>]]
```

**Examples:**

* Show all environment variables

  ```cmd
  set
  ```
* Display only PATH variable

  ```cmd
  set PATH
  ```

***

### `getmac` – MAC Address Display

Shows MAC addresses of network interfaces.

**Syntax:**

```cmd
getmac
```

**Example:**

```cmd
getmac
```

***

### `systeminfo` – System Information

Displays detailed system configuration.

**Syntax:**

```cmd
systeminfo
```

**Example:**

```cmd
systeminfo
```

***

### `whoami` – Show Current User

Displays the currently logged-in username.

**Syntax:**

```cmd
whoami
```

**Example:**

```cmd
whoami
```

***

### `echo` – Print Message or Variable

Displays messages or environment variables.

**Syntax:**

```cmd
echo [<message>]
```

**Examples:**

* Print message

  ```cmd
  echo Hello, World!
  ```
* Print current user

  ```cmd
  echo %USERNAME%
  ```

***

### `attrib` – File Attributes Control

Attributes are used to control and manage the behavior and visibility of files and folders

* Read-Only (R)
* Hidden (H)
* System (S)
* Archive (A)

**Syntax:**

```cmd
attrib [+/-rhsai] <file>
```

**Examples:**

* Show file attributes

  ```cmd
  attrib nc64.exe
  ```
* Set read-only, hidden, system

  ```cmd
  attrib +r +h +s nc64.exe
  ```
* Remove attributes

  ```cmd
  attrib -r -h -s nc64.exe
  ```

***

### `copy` – Copy Files

Copies files to a new location.

**Syntax:**

```cmd
copy [/v] [/b] <source> <destination>
```

**Examples:**

* Copy a file to a folder

  ```cmd
  copy nc64.exe d1
  ```
* Copy all `.exe` files in binary mode

  ```cmd
  copy /b *.exe d1
  ```

***

### `xcopy` – Extended File Copy

Copies files/directories with advanced options.

**Syntax:**

```cmd
xcopy <source> <destination> [options]
```

**Examples:**

* Copy folder with subdirectories and hidden files

  ```cmd
  xcopy C:\tools D:\backup /s /e /h
  ```
* Show help

  ```cmd
  xcopy /?
  ```

***

### `robocopy` – Robust Copy

Advanced tool for mirroring or bulk file copying.

**Syntax:**

```cmd
robocopy <source> <destination> [<file(s)>] [<options>]
```

**Example:**

* Copy all `.png` files with subfolders and verbose output

  ```cmd
  robocopy C:\ "C:\Users\Administrator\Downloads\d2\png" *.png /S /V /IS /IT
  ```

***

### `takeown` – Take File Ownership

Takes ownership of a file or directory.

**Syntax:**

```cmd
takeown /F <file_or_folder> [/A] [/R] [/D Y]
```

**Example:**

* Take ownership recursively as admin group

  ```cmd
  takeown /F "C:\Restricted\file.txt" /A /R /D Y
  ```

***

### `shutdown` – Shutdown or Restart

Performs system shutdown or restart operations.

**Syntax:**

```cmd
shutdown [options]
```

**Example:**

* Immediate forced shutdown

  ```cmd
  shutdown /s /f /t 0
  ```
