Skip to content

Instantly share code, notes, and snippets.

@flexd
Last active December 11, 2015 00:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flexd/01d8fb3d3a9b4b146bf1 to your computer and use it in GitHub Desktop.
Save flexd/01d8fb3d3a9b4b146bf1 to your computer and use it in GitHub Desktop.
I've been compiling a list of useful linux commands and tools I've been using over the past few months. This is it.
# Tips & useful commands
watch -n 1 -d <command> # run a command periodically and show the output, -n specifies interval, -d highlights changes.
ctrl-x e # Invoke a editor to write a tricky long command.
reset # Fixed a broken terminal.
ssh-copy-id user@host # Copy SSH public keys to host to enable password-less SSH logins.
sudo <command> # DANGEROUS Run a command as root, requires you to be in /etc/sudoers or a group that is, DANGEROUS.
sudo !! # DANGEROUS. Run the last command as root. DANGEROUS
column -t # Pipe any command to column -t to get a nice aligned output.
apropos <word> # Search man pages.
lsof -p <PID> # See what files a process has open.
ps auxww -H # See all processes, with params + hierarchy.
pgrep -fl node # See all node-related PIDs and processes.
cd - # Change to last working dir
strace -f -p <PID> # See what a process is doing (system calls), -f traces child processes (results of fork()), -p specify pid.
tail -f file.log | grep 10.0.0.1 # Monitor a log file (or any file) for a string.
!!:gs/foo/bar # Run previous command, replacing foo with bar everytime foo occurs.
ctrl+u [...] ctrl+y # type partial command, kill this command, check something you forgot, yank the command, resume typing.
# Example :
# vim /etc/fstab
# Woops, forgot sudo!
# <ctrl+u> sudo <ctrl+y>
# sudo vim /etc/fstab
ps aux | sort -nk +4 | tail # Display the top 10 running processes, sorted by memory usage.
ping -i 60 -a <ip> # Sound an audible bell alarm when a host comes online, useful for when you are waiting for something to reboot. -i is interval, -a is audible bell.
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head # Get the 10 most uses commands from your history.
# Tools
htop # Instead of top, htop is a process manager/monitor.
ranger # File manager, vim-style.
# Disk
iostat -xnk 5 # Check read/writes per disk -x is extended statistics, -n shows NFS header row, -k displays statistics in kilobytes per second instead of blocks. Use -m for megabytes per second, 5 is the interval (must be installed, in apt package sysstat)
df -h # Display an overview of all disks
du -hs # Display disk usage of this directory and all sub-directories.
find . -size +100M # Find all files in current directory over 100M.
# Memory
free -m # Show free memory, -m displays in megabytes. Learn how to read memory at: http://www.linuxatemyram.com/
cat /proc/meminfo # See information about memory
# Network
ssh -N -L2001:localhost:80 somehost # Start a tunnel from somehosts port 80 to localhost 2001. (You can go to http://localhost:2001 to hit somehost:80)
python -m SimpleHTTPServer 8080 # Serves the local directory from 8080.
lsof -i # Monitors network connections in real time.
nethogs # Shows the bandwidth usage per process. (must be installed)
netstat -tnlp # List all listening ports with PID of process.
mtr google.com # mtr is better than traceroute and ping combined.
lsof -nPi tcp # See all TCP sockets in use, -n disables hostname lookup (makes lsof faster), -P disables port name lookup, -i is used for matching addresses/protcols, like tcp.
curl -LI http://google.com # -I display HTTP headers, -L follow redirects.
iftop # Show traffic by port, install required, uses pcap.
# Performance
vmstat 1 # See state of your system, are we swapping? 1 is interval to call.
time <command> # See how long a command takes to execute.
# Vim commands
:w !sudo tee % # Save a file you edited in vim without the needed permissions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment