List of linux commands
Here is a list of linux cli commands/tools that I have used. Purpose is for my own future reference and to track what I know. The list is non exhaustive and not sorted in any way. explainshell.com is a very nice website to learn about the commands, can bookmark https://explainshell.com/explain?cmd=%s
.
Shell tools
man
: get help for commandswhich
: get first path of commandwhere
: get paths of commandalias
: set command shortcutwhoami
: get current userwatch
: runs command every n secondswatch -n5
: runs command every 5 sec
tee
: split stdin to file and stdoutxargs
: reads stdin line by line and run command for every linexargs -I{} <command> "{}"
: set each line as {} and run command with the line as first arg
set
: sets shell options, usually used at the top of a bash scriptset -euo pipefail
: bash strict modeset -euxo pipefail
: bash strict mode, also prints each line
test
: check condition and set exit code 0 for true, 1 for false, usually used in if statements[
: alias of test, for writing bash script like if [ condition ][[
: better version of [
Text operations
echo
: prints textcat
: prints file content, also used for con”cat”enating filesless
: reads file in a scrollable interface (ncurses), use j and k to scroll per line or u and d to scroll per page, q to quitmore
: older version of less, cannot scroll up
head
: reads first n lineshead -n5
: reads first 5 lines
tail
: reads last n linesgrep
: find a word or with regex in filessed
: search and replacetr
: simpler alternative to sedcut
: split string and select substringcut -d' ' -f1
: split by space, select first word
awk
: text manipulation tool, includes its own scripting language (heard of it, never used it)sort
: sort linesuniq
: deduplicate adjacent lines, usually used after sortwc
: word countwc -l
: line countsort <file> | uniq | wc -l
: count unique lines
jq
: reads json and prints selected key, includes its own scripting language
File operations
ls
: prints directory listingls -lah
: prints in detaills -lahtr
: sorted by last modified (newest first)
cd
: change directoryz
: oh-my-zsh plugin to change to recent directoryrm
: remove file/directoryrm -rf
: removes recursively
cp
: copies filemv
: moves filemkdir
: creates directorypwd
: prints working(current) directory, not to be confused with passwdtar
: compress or extract tar filestar -xzvf
: extracts .tar.gz files
gzip
: compress or extract gzip filesgzip -d
: extracts .gz file in the same dir, removing the .gz filegzip -dk
: extracts .gz file, keeping the .gz file
zless
:less
for .gz file without extracting itzcat
:cat
for .gz file without extracting itzgrep
:grep
for .gz file without extracting itzip
: compress to .zipunzip
: extracts .ziptouch
: creates file, sets last modified timechmod
: change file permissionschmod +x
: make file executable
ln
: creates symbolic linkfind
: find a file by filename
System tools
uname
: prints OS nameuname -a
: prints all OS info
env
: prints all env vars #!/usr/bin/env bash: runs bash specified in $PATH, usually used in first line of bash scriptexport
: sets user env varreboot
: restarts machinechroot
: treat directory as fake root dir, containers are built upon this (heard of it, never used it)lshw
: lists all hardware infolscpu
: prints cpu infodf
: show disk utilization
Process tools
ps
: list running processesps aux
: list allps ef
: alternative to ps aux
htop
: like task manager in windows, view system resourcestop
: older colourless version of htopdstat
: prints system resource utilization every secondkill
: kills process by sending SIGTERMkill -9
: kills using SIGKILL (cannot be caught by process)kill -s
: kills using specified signal
Network tools
netstat
: list open portsnetstat nltp
: list all TCP listening ports and its process, may need sudo
ss
: alternative to netstatifconfig
: like ipconfig in windows, shows local IP addressip
: alternative to ifconfigip a
: show ip address
ping
: like ping in windows, sends ICMP packet to check if address is accessible and measure round trip timetracert
: measure hop by hop round trip timedig
: like nslookup in windows, runs dns lookupssh
: provides a shell to access remote machinescp
: file transfer over sshrsync
: more optimized alternative to scppssh
: sends ssh commands in parallel to multiple machinesi2cssh
: only for iterm2, opens multiple iterm2 panels to ssh into multiple machines (feels very hackery lol)who
: see who else is ssh-ing into the same machinecurl
: send http request, also includes various other protocolscurl -fsSL
: send request non verbose, follows http redirectscurl -X POST -d 'param1=value1¶m2=value2'
: posts x-www-form-urlencodedcurl -X POST -H 'content-type: application/json' -d '{"a":"b"}'
: posts jsoncurl -F 'image=@file.jpg' -F 'param=value'
: posts multipart/form-data
User permission
sudo
: runs as rootsudo -s
: change as root user, use my default shell, start in same directory
passwd
: change password
Other tools
bc
: basic calculatordate
: prints current datetime
Shells
zsh
: Z shell, popular cos of oh-my-zsh, default shell of MacOS, Archbash
: Bourne again shell, popular cos default shell of Ubuntush
: symbolic link to default shellfish
: fish shellchsh
: change default shell
Text editors
vim
: very customizeable, not too beginner friendly text editorvi
: older alternative to vimnvim
: neovim, newer alternative to vimnano
: beginner friendly text editor
Git
git
: version control system, best to alias all the commands using oh-my-zsh git plugingit status
: show statusgit log
: show commit historygit log --all --decorate --oneline --graph
: pretty log
git add
: stages filegit commit
: commits staged changesgit commit -m
:git commit --amend --no-edit
: rewrite previous commit with staged changes
git push
: pushes commitsgit push -f
: force overwrite remote commitsgit push --force-with-lease
: force if no newer commits on remote
git pull
: pulls commitsgit reset
: unstage changesgit reset HEAD~
: undo previous commitgit reset --hard HEAD~
: undo previous commit and undo changes in working directory
git checkout
: change branchgit checkout -b
: create new branch and change branch
git merge
: merge branchesgit remote
: show remote namegit remote -v
: list remote repos
git rebase
: moves branch’s base commit up to latest by rewriting commits, good for keeping clean history, bad if you’re working in a teamgit rebase -i
: interactive rebasegit rebase --abort
: cancel ongoing rebase
git reflog
: list history of commits accessed in local repo, useful if you lost reference due to rebase or if you mess up rebasing
Docker
docker
: for docker containersdocker pull
: downloads imagedocker run
: run containerdocker run -it <container> /bin/bash
: enter the container (like ssh into container)
docker images
: list imagesdocker ls
: list containersdocker login
: saves credential to remote docker registry (for pulling/pushing images)
Package managers
apt
: for ubuntubrew
: for macnpm
: for nodejspip
: for pythonpython -m venv .venv
: create virtual env . .venv/bin/activate: enter virtual envvirtualenv -p <path to python2> .venv
: create virtual env for python2
cargo
: for rustgo get
: for golanggem
: for rubyfpm
: effing package management, creates various packages
Version managers
pyenv
: for pythonrbenv
: for rubyrvm
: alternative to rbenvnvm
: for nodejs
Fancy tools
ranger
: file explorer in terminalncmpcpp
: mpd client for playing music in terminal