Skip to content

Instantly share code, notes, and snippets.

@kohrongying
Last active April 24, 2020 04:34
Show Gist options
  • Select an option

  • Save kohrongying/9d702726dccbdbc082d7cf3751d31234 to your computer and use it in GitHub Desktop.

Select an option

Save kohrongying/9d702726dccbdbc082d7cf3751d31234 to your computer and use it in GitHub Desktop.
General OS Commands

NETSTAT

sudo netstat -nap | grep nginx

netstat -an | grep :1935 | grep ESTABLISHED | wc -l ## Returns # connections

netstat -tulpn 

netstat -tulpn | grep :80

NETWORKING

dig lookup
dig +short mx example.com
dig +short ns example.com

PSQL

# login as postgres user
psql -U postgres

# list all databases
psql -l

# quit
\q

# connect to db
\c database

# show tables
\dt

# list users
\du

TMUX

sudo apt-get update
sudo apt-get install tmux
  • tmux list-sessions
  • Ctrl-b then d - To detach
  • tmux attach -t <session-name> - To attach

UBUNTU

tar -zxvf name.tar.gz
unzip dev.zip
apt get unzip
  • echo "stuff" > README.md - write / overwrite file
  • echo "add stuff" >> README.md - append to file
  • ps axuf - process status displays information of all active processes
  • ps -e - displays all the current process
  • sudo /usr/local/nginx/sbin/nginx -s restart
  • sudo /usr/local/nginx/sbin/nginx -s reload
  • lsof -wni tcp:3000 - find process on port 3000
  • kill -9 <pid> - kills process of process # pid
  • cat / head / tail filename.txt - displays entire / start / end of file
  • echo hello > foo.txt - redirect into file, creates file if not exist, overwrites if exists
  • echo hello >> foo.txt - appends to file
  • grep my_regrex my_file - search and returns whole line of file for each match
  • grep -i my_regex my_file - -i makes the search case insensitive.
  • grep -v my_regex my_file - return all lines that don’t contain my_term. -vreturns the inverse, like not in many languages.
  • grep -c my_regex my_file - return a count of how many times a match is found with -c.
  • grep -R my_regex my_folder - recursively search all files in the folder and all subfolders with -R.
  • ag my_regex my_file - returns the line number and the line with any matches.
  • ag -i my_regex my_file -  -i for case insensitive .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment