Linux CLI Tools


Basics

ln -s /path/to/existing/file /path/to/create/link/in

df -h
(human readable disk space free)

lsblk
(file systems to disk)

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 8G 0 disk
├─nvme0n1p1 259:1 0 8G 0 part /
└─nvme0n1p128 259:2 0 1M 0 part

ssh-add -K ~/.ssh/keyfile

ssh-keygen -t rsa -b 4096 -o -a 100
(generate a more secure 4096-bit ssh key than the default ssh-keygen)

head -n 1000 hugefile.txt > first1000lines.txt

tail -f logfile.txt
shows last 15 lines and follows updates to the file

screen
screen -r
(reconnects to existing terminal that stays running after ssh session ends)

tar zcvf ~/source.tgz path/to/expand/at

\ls
(runs a bare ls without trying to figure out which are folders/files, useful for large network directories that normal ls takes forever to output)

find . -mtime -1 -ls
(finds files changed in the last 24h)

sudo usermod -a -G newGroup username

sudo chmod g+w file
(add group write permission)

traceroute -q 1 -m 50 -w 1 zazeski.com
fast lookup since so many routers discard ICMP traffic
(only 1 per hop with 1 sec timeout, stop at 50 hops)

Bash Snippets

#! /bin/bash

YESTERDAY_DAY_LINUX=`date -d "yesterday 13:00" '+%d'`
YESTERDAY_DAY_MAC=`date -v-1d +%d`
YESTERDAY="${YESTERDAY_DAY_LINUX}${YESTERDAY_DAY_MAC}"
date -u +"%Y-%m-%d" #2019-03-25

VAR="test"
echo ${VAR}

ls > /path/to/log
ls >> /path/to/log/and/append

.bashrc

# some more ls aliases
alias ll='ls -alFh'
alias la='ls -A'
alias l='ls -CF'

# Node Version Manager (NVM)
export NVM_DIR="$HOME/.nvm"¬
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm¬
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion¬

Netem (simulating poor network conditions)

sudo tc qdisc add dev eth0 root netem delay 100ms (add 100ms delay to eth0)

sudo tc qdisc delete dev eth0 root netem delay 100ms (remove 100ms delay to eth0)

VIM

ddkP
Move the current line up one (by deleting the line, saving to buffer and pasting it back in)

Docker

docker ps -al

docker pull

docker system prune #removes dangling images

docker system prune -a #aggressively removes all not currently running images

docker logs --tail 100 containername

GIT

You just messed up and pushed something to origin that you should not of –no one else has pulled yet, quick undo it before anyone pulls.

git reset --hard HEAD~1
git push --force

You want to remove an existing remote GIT server to add a new one named origin (you can also edit it but this lets you copy/pate from github/bitbucket)

git remote remove origin
git remote add origin git@bitbucket.org:project/website.git
git push -u origin master

Additional 3rd Party Tools

ncdu (ncurses disk utlility)
great tool to find where all your disk space is being used on linux
(q to exit)

sudo apt install ncdu
sudo yum install ncdu

nmap (network mapping) - port scanning
ntop - like top but for networks
ctop - docker container top
htop -
tldr - short man pages about


I'm a 31 year old UIUC Computer Engineer building mobile apps, websites and hardware integrations with an interest in 3D printing, biotechnology and Arduinos.