Skip to content

Terminal Cheatsheet

Print-friendly reference for essential terminal commands

CommandDescriptionExample
pwdPrint working directorypwd
lsList files and foldersls
ls -laList with details + hiddenls -la
cd folderChange directorycd Documents
cd ..Go up one levelcd ..
cd ~Go to home directorycd ~
cd -Go to previous directorycd -

File Operations

CommandDescriptionExample
touch fileCreate empty filetouch index.js
mkdir folderCreate directorymkdir src
cp source destCopy filecp a.txt b.txt
cp -r src destCopy foldercp -r old new
mv old newMove or renamemv old.txt new.txt
rm fileDelete filerm temp.txt
rm -rf folderDelete folderrm -rf node_modules

DANGER

rm is permanent! There is no trash can.

Viewing Files

CommandDescriptionExample
cat fileShow file contentscat package.json
head fileShow first lineshead -20 file.txt
tail fileShow last linestail -20 file.txt
less fileScrollable viewless log.txt

Searching

CommandDescriptionExample
grep pattern fileFind in filegrep "error" log.txt
grep -r pattern dirFind in foldergrep -r "TODO" src
find . -name "*.js"Find filesfind . -name "*.tsx"

Utilities

CommandDescriptionExample
clearClear screenclear
historyShow command historyhistory
which cmdFind command locationwhich node
echo textPrint textecho "Hello"

npm Commands

CommandDescription
npm initInitialize new project
npm installInstall dependencies
npm install pkgAdd a package
npm run scriptRun a script
npm run devStart dev server
npm run buildBuild for production
npm run lintRun linter

Shortcuts

ShortcutAction
TabAutocomplete
Tab TabShow all options
↑ / ↓Previous/next command
Ctrl + CCancel current command
Ctrl + LClear screen
Ctrl + RSearch history
Ctrl + AGo to line start
Ctrl + EGo to line end

Special Paths

PathMeaning
.Current directory
..Parent directory
~Home directory
/Root directory

Combining Commands

bash
# Run if previous succeeds
cmd1 && cmd2

# Run regardless
cmd1 ; cmd2

# Pipe output
cmd1 | cmd2

Print this page for quick reference!

Built for learning | Open source on GitHub