My top 10 Linux command line tools

When you’re using a *nix based operating system (Linux, OS X etc.) it’s easy to underestimate the power and speed of the command line. Here’s a list of my top 10 cli tools.

10. lsof
lsof gives you a list of every currently open file on the system in addition it provides a ton of other useful info such as who has the file open and if applicable what program and process has it open.

09. cat
cat outputs the provided file to the screen. Very useful when you want to pipe ( | ) the output to another program. (I’ll go more in depth on piping in a later posting)

08. top
top shows us a listing of the “top” running processes (top is reatlive it can show the “top” memory consumers, “top” cpu users etc.) The beauty of top is that it updates in real time.

07. dig
dig is similar to (but more powerful than) nslookup for Windows. You can use dig to do DNS lookups. For example if I wanted to find the IP address for a host like say , www.pownce.com I’d run the following query
dig A www.pownce.com
telling dig I’d like to do an “A” record lookup on www.pownce.com. I’ll then get the following result.

; <<>> DiG 9.4.1-P1 <<>> A www.pownce.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63464
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 4

;; QUESTION SECTION:
;www.pownce.com. IN A

;; ANSWER SECTION:
www.pownce.com. 1126 IN A 64.27.4.226

;; AUTHORITY SECTION:
pownce.com. 71348 IN NS ns1.everydns.net.
pownce.com. 71348 IN NS ns2.everydns.net.
pownce.com. 71348 IN NS ns3.everydns.net.
pownce.com. 71348 IN NS ns4.everydns.net.

;; ADDITIONAL SECTION:
ns1.everydns.net. 138211 IN A 208.76.56.56
ns2.everydns.net. 138211 IN A 204.152.184.150
ns3.everydns.net. 138211 IN A 208.96.6.134
ns4.everydns.net. 138211 IN A 64.158.219.3

;; Query time: 62 msec
;; SERVER: 64.253.129.3#53(64.253.129.3)
;; WHEN: Sun Nov 18 22:46:43 2007
;; MSG SIZE rcvd: 196

Which shows us that www.pownce.com resolves to the IP address 64.27.4.226
dig has a whole bunch more options and command line switches I’ll go into this further if there’s interest.

06. scp
I don’t think I’ve gone through an entire day without using scp. The scp command allows you to copy files to or from any machine running an ssh server you can even copy something from a remote machine to another remote machine (Which should be any *nix box worth it’s salt) It’s fast it’s quick and it’s easy and doesn’t involve any sort of mounting. One of the enjoyable side effects is that all the data is encrypted from machine to machine (we always like encryption). Syntax is “scp source destination” if the source or destination is remote you need to preface the filename with username@hostname: so if I wanted to copy a file named test.txt in the root folder of my local machine to my home folder on a remote server named host.server.org I’d run ” scp /test.txt myusername@host.server.org:~ ” (~ is a shortcut to your home folder).

05. ps
ps shows every running process for the current user. It’s invaluable for finding the pid or process ID of a program you need to kill.

04. tail
Tail shows you the last 10 lines of a file. I use this almost every day to check the recent output from a log file. Were this become especially useful to me is when you add the command line argument ” -f ” this makes tail continue to update in real time. so you can watch a log file for example update in real time. I use this to watch email logs when I’m testing mail accounts or potential problems.

03. screen
screen is a whole subject in and of itself. It’s almost like a window manager for the terminal. It has a plethora of keyboard shortcuts that allow you to send a terminal to the background while allowing the program to continue running. Where I use this is in running things like Half-Life 2 death match servers. They output a lot of data to the screen and it’s nice to be able to start them running background them and then be able to pull up those terminal sessions again to run a couple commands or just watch the console output. I could write an essay on all the options and shortcuts in screen so I’ll cut this off here.

02. vi
This is my de-facto text editor I know the whole emacs vs. vi debate still rages. But I tend to think that most people simply become comfortable with whatever they learned first and that was vi for me. vi is one of those programs where I’m probably using about 2% of the power available to me and I find that oddly comforting. There will always be shortcuts for me to find to make my work day easier or less redundant. I can’t go a single workday without having vi open for 50% or more of it.

01. grep
grep is a decent search utility but that’s not the power to me. Where I find the power is combining it with other commands such as tail or cat. What grep does is return a line in which it finds a match (you can alter this to include lines before or after as well). What I often do is if I’m having problems with a specific email address for example I’ll tail -f the mail log file but pipe ( | ) it to grep so

tail -f /var/log/mail.log |grep email@address.com

so if I leave this running for a while I’ll come back and any lines that have been added containing “email@address.com” will now be showing on my screen.

Well I hope this has put someone on to at least one command they’ve ignored or underused. Please let me know what your most used command line apps or commands are.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Published by

LiamM

I'm a self labeled Nerd who enjoys Playing Video Games, restoring classic muscle cars (i have a 65' Mustang in the works) , Running Big Data Clusters, Tattoos, Working on System Automation, Riding and customizing Motorcycles, and writing python Code. I'm an SRE with DemonWare/Activision Specializing in Big Data/Hadoop operations but all opinions and views expressed on this site are solely my own.