CLI Navigating the Command Prompt


Navigating the Command Prompt in Windows CLI involves moving through directories, viewing directory contents, and understanding your current location within the file system. Here’s a guide to mastering navigation commands in the Command Prompt.

1. Opening the Command Prompt

  • Press Win + R, type cmd, and press Enter.
  • Alternatively, search for "Command Prompt" in the Start menu.

2. Checking Your Current Directory with cd

  • The prompt shows the current directory by default, like this:
    C:\Users\YourName>
  • To verify or display the current directory at any time, simply type:
    cd

3. Changing Directories with cd

  • To move into a directory:
    Use the cd command followed by the directory name.

    cd FolderName

    Example:

    cd Documents

    This moves you from the current directory to the Documents folder.

  • To go back to the previous directory:
    Use cd .. to move up one level in the directory structure.

    cd ..
  • To switch to a specific path:
    Enter the full path to navigate directly to that folder.

    cd C:\Users\YourName\Desktop
  • To change drives:
    Use the drive letter followed by a colon (:) to switch between drives.

    D:

4. Listing Directory Contents with dir

  • Use the dir command to display files and folders in the current directory:
    dir
  • With options:
    • dir /p: Displays results one page at a time (helpful for long lists).
    • dir /s: Shows all files and subdirectories in the current directory and its subdirectories.
    • dir /a: Shows hidden files and system files.

5. Creating Directories with mkdir

  • To create a new directory (folder) within the current directory:
    mkdir NewFolder

6. Moving Between Directories Quickly

  • Use Tab Autocomplete: Start typing a directory or file name and press Tab to autocomplete names in the current directory.

7. Viewing Directory Path with echo %cd%

  • The echo %cd% command outputs the full path of the current directory.
    echo %cd%

Examples of Navigation

C:\Users\YourName>cd Documents // Navigates to the Documents folder C:\Users\YourName\Documents>dir // Lists contents of the Documents folder C:\Users\YourName\Documents>cd .. // Moves up to the parent directory C:\Users\YourName>cd Desktop // Navigates to the Desktop C:\Users\YourName\Desktop>mkdir Test // Creates a new folder named Test C:\Users\YourName\Desktop>cd Test // Navigates into the Test folder C:\Users\YourName\Desktop\Test>echo %cd% // Displays the full path of Test folder

Quick Tips

  • Use cd /d <drive>: Changes directories and drives simultaneously.
  • dir /b: Lists files and folders in a bare format, without extra details.

Mastering these navigation commands will make it easier to work with files, directories, and drives directly from the Command Prompt, allowing for quicker and more efficient navigation throughout your file system.