Windows command cheat sheet

1. Basic Navigation

  • cd
    Displays the current directory path.
  • dir
    Lists all files and directories in the current directory.
  • cd [directory]
    Changes the directory to the specified one.
    Example:
    cd Documents
  • cd ..
    Moves up one directory level.
  • cd \
    Changes to the root directory of the current drive.
  • cd /d [drive_letter]:\[directory]
    Changes to a different drive and directory.
    Example:
    cd /d D:\Projects

2. File Management

  • type [filename]
    Displays the contents of a file.
    Example:
    type index.html
  • copy [source] [destination]
    Copies a file to a new location.
    Example:
    copy index.html backup_index.html
  • move [source] [destination]
    Moves or renames a file or directory.
    Example:
    move index.html new_index.html
  • del [filename]
    Deletes a file.
    Example:
    del index.html
  • rmdir [directory_name]
    Deletes a directory (only if it's empty).
    Example:
    rmdir my_project
  • rmdir /s [directory_name]
    Deletes a directory and all its contents.
    Example:
    rmdir /s my_project
  • mkdir [directory_name]
    Creates a new directory.
    Example:
    mkdir my_project

3. Viewing and Editing Files

  • notepad [filename]
    Opens a file in Notepad for editing.
    Example:
    notepad index.html
  • more [filename]
    Displays the contents of a file one screen at a time.
    Example:
    more index.html

4. Search and Find

  • find "[text]" [filename]
    Searches for a specific term within a file.
    Example:
    find "title" index.html
  • dir [directory] /s /p
    Searches for files and directories, showing results page by page.
    Example:
    dir *.html /s /p

5. Permissions

  • attrib +r [filename]
    Sets a file as read-only.
    Example:
    attrib +r index.html
  • attrib -r [filename]
    Removes the read-only attribute from a file.
    Example:
    attrib -r index.html

6. Networking

  • ping [hostname]
    Checks the network connection to a server.
    Example:
    ping google.com
  • ipconfig
    Displays your current network configuration.
  • tracert [hostname]
    Traces the path packets take to reach a network host.
    Example:
    tracert google.com

7. Version Control (Git)

  • git clone [repository_url]
    Clones a remote Git repository to your local machine.
    Example:
    git clone https://github.com/username/repository.git
  • git status
    Shows the current status of your Git repository.
  • git add [filename]
    Adds a file to the staging area.
    Example:
    git add index.html
  • git commit -m "[message]"
    Commits the staged files with a message.
    Example:
    git commit -m "Initial commit"
  • git push
    Pushes your commits to the remote repository.

8. Miscellaneous

  • cls
    Clears the terminal screen.
  • exit
    Closes the terminal session.
  • echo [text]
    Displays a line of text.
    Example:
    echo Hello, World!
  • history
    Displays a list of recently used commands (if Command Prompt was launched with history enabled).