Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Best UNIX shell-based tools I can't live without with example usages

Best UNIX Shell tools

These are a list of usages of shell commands I can't live without on UNIX-based systems.

Install

Mac OS X

Using Homebrew (yes, I am opinionated) you can install the following tools with the following packages:

brew install proctools # to install pgrep, pkill, etc.
brew install pstree # to be able to use pstree
brew install vnstat # to be able to use vnstat
brew install ncdu # to use ncdu
brew install ipcalc # to use the almighty ipcalc
brew install htop # to use htop
brew install ack # to use the awesome ack
brew install lsof # to use the amazing lsof

Fedora/Red Hat/CentOS

Using YUM you can install the tools with the following RPM packages:

yum install proctools # same as brew package
yum install psmisc # for pstree
yum install vnstat # for vnstat
yum install ncdu # for ncdu
yum install initscripts # for ipcalc - should already have this, I think?
yum install htop # for htop
yum install ack # for ack
yum install lsof # for lsof

Ubuntu/Debian APT

Using APT you can install the tools with the following RPM packages:

apt-get install procps
apt-get install psmisc
apt-get install vnstat
apt-get install ncdu
apt-get install ipcalc
apt-get install htop
apt-get install ack
apt-get install lsof
#!/usr/bin/env bash
ncdu # launches ncurses version of `du` that makes it nice to navigate around in
pgrep -L beam.smp # lists all Erlang processes
pkill ruby # kills all Ruby processes
fc # opens previous command in your $EDITOR then after editing line, will execute on editor quit
fc pgrep # opens last command starting with pgrep in $EDITOR
lsof -iTCP # show current TCP connections
lsof -i :8080 # show current connections on port 8080
lsof -i@your.remote.host # show all connections to/from your.remote.host
lsof -u `whoami` # show all your user's connections
lsof -c beam.smp # show all connections for Erlang nodes
lsof /path/to/file # show all OS processes using or pointing to that file path
lsof -p 4830 # show all connections for a specific PID (4830)
lsof -a -u USER -c beam.smp # show all connections for Erlang nodes running as USER
/etc/init.d/nginx stop
sudo !! # runs previous command but prefixes sudo before it (can use anything instead of sudo, the key is !!)
^stop^start # reruns previous command but substitutes stop for start
vim /really/long/path/to/file.crap
ghc !$ # use argument from previous command using !$...can prefix with anything, just an example usage with ghc.
vnstat -l 1 -i eth0 # show live transfer counters for interface eth0
ack "text/pattern to search for" # equivalent to a faster fgrep for all files in current directory or under (recursively)
htop # shows colourful version of top with CPU ASCII art display :)
ipcalc 192.168.0.1/32 # displays information about resulting broadcast network, very very useful!
pstree -u USER # show process tree for all procs running as USER
pstree -p PID -l 2 # show process tree for all procs under PID at 2 levels deep
echo "Enjoy and heckle me on Twitter @SusanPotter if you want to tell me what commands you can't live without not in this usage script! :)"
@geekbrit

This comment has been minimized.

Copy link

@geekbrit geekbrit commented Dec 6, 2011

Do you intend to add a file for useful aliases? I don't have many, the one I use the most is the incredibly brain-dead "alias hgr='history | grep $1'"

@mbbx6spp

This comment has been minimized.

Copy link
Owner Author

@mbbx6spp mbbx6spp commented Dec 6, 2011

I have a few .alias files already in my .home repo, but not sure I have committed all my current aliases. I actually usually don't alias lsof much, simply because I learned it so well previously, but I imagine those would be great candidates for others.

I sort of see aliases as pretty personal things (like a .vimrc or .emacs file), but you are welcome to comb through my .home repo at https://github.com/mbbx6spp/.home

@mbbx6spp

This comment has been minimized.

Copy link
Owner Author

@mbbx6spp mbbx6spp commented Dec 6, 2011

@geekbrit this is probably the most common alias file I have that gets sourced when my shell is either bash or zsh: https://github.com/mbbx6spp/.home/blob/master/dotfiles/profile.d/global.aliases

Note: I recently went from zsh to bash because I was using RVM (Ruby Version Manager) and it killed the version of zsh I was using for a while, so some of the aliases commented out were actually Zsh specific (e.g. the extra option to alias built-in for non-prefix aliases).

@bric3

This comment has been minimized.

Copy link

@bric3 bric3 commented Feb 24, 2012

Too bad htop is not anymore in the standard homebrew repo.
lsof however is already available in osx.

@dvorka

This comment has been minimized.

Copy link

@dvorka dvorka commented May 6, 2014

@paulbjensen

This comment has been minimized.

Copy link

@paulbjensen paulbjensen commented Dec 15, 2017

This is a great list, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.