Skip to content

Instantly share code, notes, and snippets.

@somahargitai
Last active June 6, 2022 18:03
Show Gist options
  • Save somahargitai/a544dcef4660e19bf28a6928f4bad46d to your computer and use it in GitHub Desktop.
Save somahargitai/a544dcef4660e19bf28a6928f4bad46d to your computer and use it in GitHub Desktop.
Command Line Cheatsheet

cheatsheet list

Command Line tips and tricks

  • For Mac/Linux commands check my other Gist
  • I list DOS commands below but it is highly recommended to use the last version of Powershell (version 6+) instead. It began the default command line tool in Windows and provides a wider range of options. Some commands are not supported in Powershell directly. You can use them with cmd /c. For example to use assoc type cmd /c assoc.
  • for learning Powershell you can check this article

contents:

  1. My favourites
  2. Basics
  3. Advanced
  4. Editors
  5. Environment

1) My favourites

  • List line from a text source (history) contains a keyword (git):
    Get-History | sls -Pattern "git" env | grep AWS

2) Basics

command description
sl ~ go to home directory C:\Users\User>
cd / go to root directory C:\>
help dir print help documentation of any command
cd, dir moving, viewing - while dir is the classical DOS command, in Powershell we can use other Get-ChildItem aliases, like gci or the Mac/Linux-like ls. For hidden files use -Force flag. Likewise the classic cd can be used in Powershell as it is a default alias for Set-Location, just like sl
mkdir xfolder, New-Item info.log, ni info.log, del *.log, rm *.log create an xfolder folder, create info.log file, delete all the files with .log ending (similarly del abc* deletes files having the prefix abc... )
explorer . open a Windows explorer with the currect location
mv /home/jack/testfile /home/jack/testfile2 move testfile from its lication to the new location as testfile2
assoc, ftype list file associations with programs and their locations (for example: .jpg to IrfanvView)
systeminfo list computer name, manufacturer, OS version and install date etc.
ipconfig list computer ip
arp -a list network elements' IP, physical address and if they are static or dynamic
gci env:*, gci env:JAVA_HOME, SET list environmental variables or print a specific one. SET is the original DOS command but it has a different functionality in Powershell
Get-History, F8 terminal command history (terminal-window related so don't trust it too much)
grep search text. It can be used in terminal like grep text in filename see examples here but it is also very common to pipe an output to it. For example: history | grep code extracts all the commands from terminal history where we opened a file with VS Code
pipe | read from standard output and pass it as a parameter to some function
cat index.html read file to standard output (practically: print to console)
sls "findthistext" index.html find the given test in the file with Select-String alias sls
tail -100 index.html read last 100 lines of a file to standard output
wc index.html count characters, words and lines in a specific file
date print date
tree print folder tree

3) Advanced

  • find your running server and stop it You can do it by listing the running processes on your computer. If you have a running server (like Node.js or Tomcat) on a port (like 8080, 3000 etc.), you will see in the list that your server is there, like 0.0.0.0:8080. Copy the identifier of that process and stop it like below!

    Command Line: netstat -aon | find /i "listening"
    Powershell: netstat -aon | Select-String -Pattern "listening"
    taskkill /F /PID 11224

command description
driverquery -v list drivers with details
tracert, ping, pathping ping an IP or URL to tests its availability
tasklist list running tasks

4) Editors

5) Environment

For handling environmental variables in Windows command line (CMD), [check out this StackOverflow article.]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment