DEV Community

Cover image for Terminal Cheat Sheet πŸ”₯ - The most useful terminal commands πŸš€
Lorenzo for World In Dev

Posted on • Edited on

Terminal Cheat Sheet πŸ”₯ - The most useful terminal commands πŸš€

Hello world! Here is a list of the basic terminal commands you should know by heart.

πŸ”– - Bookmark the article to save the cheat sheet

And remember to smash that like button ❀️ and maybe πŸ¦„

Alt Text

You absolutely need to read that:

Basics

I love the git bash (I'm on windows) - version 4.4.23

Git Bash emulates a bash environment on windows. It lets you use all git features in command line plus most of standard unix commands.

  • 3 basics commands to remember:
Clear: type "clear" / ctrl + l (windows - Linux) / Command + K (Mac)
help - show all comands
help commandName - help about a specific command
ctrl+D or ctrl+C * 2 to exit 
Enter fullscreen mode Exit fullscreen mode

Working with Directories:

ls - list / list the contents on your current directory
ls -la - Give more information about the list 
pwd - Print Working directory / Print the path to the working directory
cd directory - Change directory / Move between folders - Relative Path (just folders directly contained in the one you are currently)
cd /firstDirectory/secondDirectory/FinalDirectory - Absolute Path (search a directory anywhere in pc)
cd .. - Go back a directory
cd ~ - return to the home directory
mkdir - make directory / create a new directory+
mkdir -v - Make directory + add lines that say you created a directory
touch - Create a file (or multiple) or "touch", change a file (update when it was last modified)
rm - Remove / Delete a File (forever)
rm -rf - Remove recursive force / Delete a directory add all file nested in the directory (also other directories)
rmdir - remove a directory (only work on empty folders)
Enter fullscreen mode Exit fullscreen mode

More readable way:

image


Basic commands:

Write: help to access

image

Git available commands:

image

Write: git --help to access


image

Write: git help -g to access


Extra: Writing git help git the command line redirect you to a download with all the git bash available commands in a more readable way

Type git help -a to have access to a more advanced line by line commands description - Write q to exit


Hope this helped!

And remember to smash that like button ❀️ and maybe πŸ¦„


You added:

# opens .zprofile for editing (zsh profile)
alias prof='nano /<<ROOTDIRECTORYHERE>>/.zprofile' 
# opens .zshrc for editing
alias rc='nano /<<ROOTDIRECTORYHERE>>/.zshrc' 
# source profiles (should be done every time after changing profile)
alias s='source /<<ROOTDIRECTORYHERE>>/.zprofile; source /<<ROOTDIRECTORYHERE>>/.zshrc;'
# fancy ls
alias lk='ls -lhkart'
# for 'lk' typos ;)
alias kl='ls -lhkart' 
# open current folder in GUI
alias show='open .'
# go back a folder
alias back='cd ..'
# previous folder
alias prev='cd -'
# cd with no arguments brings you to your root folder :)
alias home='cd'
Enter fullscreen mode Exit fullscreen mode

cd (without args) - Return to the home directory

pushd and popd.

The pushd command saves the current working directory in memory so it can be returned to at any time, pushd moves to the parent directory. The popd command returns to the path at the top of the directory stack.[5][6] This directory stack is accessed by the command dirs in Unix or Get-Location -stack in Windows PowerShell.
Learn more

Other articles:

Recommended reading!


Subscribe to my Newsletter!

A loooong, and fun, weekly recap for you
Free PDF version of my articles
Highly customizable inbox
That's --> free <-- and you help me!

Top comments (7)

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

These are quite useful.

mkdir -p # or npx mkdirp
rm -rf # or npx rimraf, also trash-cli
cd - 
Enter fullscreen mode Exit fullscreen mode

Also, don't forget that TAB usually helps.

Collapse
 
fullstackchris profile image
Chris Frewin • Edited

πŸ‘ for cd -
Brings you to the previous location you were at :)

I always keep these alias with me on all machines, local and remote:

# opens .zprofile for editing (zsh profile)
alias prof='nano /<<ROOTDIRECTORYHERE>>/.zprofile' 
# opens .zshrc for editing
alias rc='nano /<<ROOTDIRECTORYHERE>>/.zshrc' 
# source profiles (should be done every time after changing profile)
alias s='source /<<ROOTDIRECTORYHERE>>/.zprofile; source /<<ROOTDIRECTORYHERE>>/.zshrc;'
# fancy ls
alias lk='ls -lhkart'
# for 'lk' typos ;)
alias kl='ls -lhkart' 
# open current folder in GUI
alias show='open .'
# go back a folder
alias back='cd ..'
# previous folder
alias prev='cd -'
# cd with no arguments brings you to your root folder :)
alias home='cd'
Enter fullscreen mode Exit fullscreen mode


πŸ‘

Collapse
 
lorenzoblog profile image
Lorenzo • Edited

Thanks, I'll add the list in the cheat sheet!

Collapse
 
barelyhuman profile image
Reaper

If you'd like to go ahead and get a workflow to use with this
dev.to/barelyhuman/my-git-workflow...

also, if you use zsh with zsh-suggestions setup, it'll reduce you the time of re-writing frequent commands.

You can find the setup instructions here
stepone

Collapse
 
icecoffee profile image
Atulit Anand • Edited

PS never use rm -rf in bigger directories directly.
Like C:>

Collapse
 
trueneu profile image
Pavel Gurkov

I’d add cd (without args), pushd and popd.

Also, just a list of built-ins is not that helpful. I mean, man bash (or help, or whatevs) gives you the same. Maybe extract the most useful?

Collapse
 
rushannotofficial profile image
Rushan S J

These commands are quite useful. Any developer would find this quite useful !