Bash Cheat Sheet
Quick reference from FreeCodingCourses.com
Move around
pwd- print the folder you are in.
ls -la- list all files, long format, including hidden ones.
cd path/to/dir- change directory. cd .. goes up, cd ~ goes home.
clear- clear the screen (Ctrl+L does the same).
Files and folders
mkdir project- make a directory. -p makes parents too.
touch file.txt- create an empty file.
cp src.txt dest.txt- copy. cp -r for a folder.
mv old.txt new.txt- move or rename.
rm file.txt- delete a file. rm -r for a folder. No undo, be careful.
Look at files
cat file.txt- print the whole file.
less file.txt- scroll a long file. q to quit.
head -n 20 file.txt tail -n 20 file.txt- first / last 20 lines.
tail -f log.txt- follow a file as it grows (live logs).
Search
grep 'error' log.txt- find lines containing text.
grep -ri 'todo' .- recursive, case-insensitive, from here down.
find . -name '*.js'- find files by name pattern.
history | grep git- search your past commands.
Pipes and redirection
ls | grep .txt- pipe: send one command's output into the next.
echo hi > file.txt- write output to a file (overwrites).
echo more >> file.txt- >> appends instead of overwriting.
command 2> errors.txt- redirect error output (stderr).
Permissions and processes
chmod +x script.sh- make a file executable.
./script.sh- run a script in the current folder.
sudo command- run as administrator. Use with care.
ps aux | grep node- find a running process; kill <pid> stops it.
Unlock the full Bash cheat sheet
You're seeing 2 of 6 sections. Drop your email to open the rest plus the gotchas, and save the whole thing as a printable PDF.
No spam, unsubscribe anytime. See our privacy policy.