Navigation#
pwd # current directory
cd - # previous directory
cd ~ # home directory
pushd /tmp && popd
Searching#
grep -rn "TODO" src/ # recursive search with line numbers
grep -ri --include="*.go" "func main" .
find . -type f -name "*.md"
find . -type f -size +100M # files larger than 100 MB
Text processing#
head -n 20 file.txt
tail -f /var/log/syslog # follow a file
wc -l file.txt # count lines
sort file.txt | uniq -c | sort -rn # count duplicates
cut -d, -f1,3 data.csv # columns 1 and 3
awk '{print $1}' access.log # first field
sed -i 's/old/new/g' file.txt # replace in place
jq '.items[].name' data.json # query JSON
Archives#
| Task |
Command |
| Create tar.gz |
tar -czf out.tar.gz dir/ |
| Extract tar.gz |
tar -xzf out.tar.gz |
| List contents |
tar -tzf out.tar.gz |
| Zip a folder |
zip -r out.zip dir/ |
| Unzip |
unzip out.zip -d dest/ |
History and shortcuts#
| Keys |
Action |
Ctrl + R |
Search command history |
Ctrl + A / Ctrl + E |
Start / end of line |
Ctrl + W |
Delete previous word |
Ctrl + L |
Clear screen |
!! |
Repeat last command |
!$ |
Last argument of previous command |
Misc#
watch -n 2 df -h # rerun every 2 seconds
time ./build.sh # measure duration
xargs -n1 echo < list.txt
curl -fsSL https://example.com -o page.html