Skip to content

Instantly share code, notes, and snippets.

@zorbash
Last active December 14, 2015 08:09
Show Gist options
  • Save zorbash/5056175 to your computer and use it in GitHub Desktop.
Save zorbash/5056175 to your computer and use it in GitHub Desktop.
I gathered some linux commands that i use a lot and consider useful.

Useful Commands Cheatsheet

Processes

Interactive Process Viewers

  • top
  • htop
  • atop

List all processes in tree format

  • ps -e -AH --forest -F

List processes in a tree format

Also show their arguments and pids

  • pstree -plUa

List by memory consumption

  • ps aux --sort pmem

Search process by command

  • ps -f -C script.rb

Search for a process by name

  • pgrep -l some_process

Trace a process

  • strace -f -p $PID

Which files are open by a process

  • lsof -p $PID

Killing Processes

Kill by name

  • pkill postgres

Packages

update installed packages

  • sudo apt-get update && apt-get update -y

search for installed package by name

  • dpkg-query -l | grep -i postgres

find where an installed package is located

  • dpkg -L <packagename>

Network

Which process is listening on which port

  • netstat -tlpu

Tcp sockets in use

  • lsof -nPi tcp

Lookup some domain's mx records

  • dig zorbash.com mx

Drop requests from a specific ip

  • iptables -I INPUT -s 66.75.84.220 -j DROP

Memory

Basic Info

  • free -m

Detailed Info

  • cat /proc/meminfo

Disk

Reads/Writes per disk

  • iostat -xnk 5

Deployments

Copying the public key to the remote server(s)

  • ssh-copy-id remote-server.org

Databases

Postgres

Create db

createdb mydb --owner your_highness

Create psql user

createuser -s your_highness #creates a superuser with username your_highness

Install postgis extension

psql -d yourdatabase -f postgis.sql

psql -d yourdatabase -f postgis_comments.sql

psql -d yourdatabase -f spatial_ref_sys.sql

Extra Resources

rubytune

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment