Skip to content

Instantly share code, notes, and snippets.

@huyttq
Created November 20, 2011 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huyttq/1380019 to your computer and use it in GitHub Desktop.
Save huyttq/1380019 to your computer and use it in GitHub Desktop.
Useful bash commands
History: Ctrl + r
Find: find /home/user -name abc.txt
Pipeline: vi `find /home/user -name abc.txt`
Ctrl-x, Ctrl-e will bring up an $EDITOR containing whatever is currently entered into the prompt. (opposed to editing last command actually entered)
Managing remote systems and trying to figure out what hardware you're on and whether it's healthy or not: dmidecode
Repeat last command with "sudo" prepended: sudo !!
Execute <command> with the argument to your previous command: <command> !$ / !* for get all args.
Show all connections with -i: lsof -i (:port_number)
Only TCP: lsof -iTCP
For a specific host: lsof -i@192.168.1.5
Pointing to a file shows what's interacting with that file: lsof /var/log/messages
The -p switch lets you see what a given process ID has open, which is good for learning more about unknown processes: lsof -p 10075.
Using -a allows you to combine search terms
You can also use the -t with -u to kill everything a user has open: kill -9 `lsof -t -u moviemasher`
Pushd pushes a directory onto a stack and switches to it. Popd removes the current directory from the stack and changes to the previous one: pushd/popd
Use it all the time to watch for incoming connections on a certain port: watch -d -n 1 "netstat -an | grep :8080"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment