10 Linux commands you’ve never used
February 19th, 2007
It takes years maybe decades to master the commands available to you at the Linux shell prompt. Here are 10 that
you will have never heard of or used. They are in no particular order. My favorite is mkfifo.
- pgrep, instead of:
You can do this:
# ps -ef | egrep '^root ' | awk '{print $2}'
1
2
3
4
5
20
21
38
39
...
# pgrep -u root
1
2
3
4
5
20
21
38
39
...
- pstree, list the processes in a tree format. This can be VERY useful when working with WebSphere or other heavy duty applications.
# pstree
init-+-acpid
|-atd
|-crond
|-cups-config-dae
|-cupsd
|-dbus-daemon-1
|-dhclient
|-events/0-+-aio/0
| |-kacpid
| |-kauditd
| |-kblockd/0
| |-khelper
| |-kmirrord
| `-2*[pdflush]
|-gpm
|-hald
|-khubd
|-2*[kjournald]
|-klogd
|-kseriod
|-ksoftirqd/0
|-kswapd0
|-login---bash
|-5*[mingetty]
|-portmap
|-rpc.idmapd
|-rpc.statd
|-2*[sendmail]
|-smartd
|-sshd---sshd---bash---pstree
|-syslogd
|-udevd
|-vsftpd
|-xfs
`-xinetd
- bc is an arbitrary precision calculator language. Which is great. I found it useful in that it can perform square root operations in shell scripts. expr does not support square roots.
Here is the script:
# ./sqrt
Usage: sqrt number
# ./sqrt 64
8
# ./sqrt 132112
363
# ./sqrt 1321121321
36347
# cat sqrt
#!/bin/bash
if [ $# -ne 1 ]
then
echo 'Usage: sqrt number'
exit 1
else
echo -e "sqrt($1)\nquit\n" | bc -q -i
fi
- split, have a large file that you need to split into smaller chucks? A mysqldump maybe? split is your command. Below I split a 250MB file into 2 megabyte chunks all starting with the prefix LF_.
# ls -lh largefile
-rw-r--r-- 1 root root 251M Feb 19 10:27 largefile
# split -b 2m largefile LF_
# ls -lh LF_* | head -n 5
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_aa
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ab
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ac
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ad
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ae
# ls -lh LF_* | wc -l
126
- nl numbers lines. I had a script doing this for me for years until I found out about nl.
# head wireless.h
/*
* This file define a set of standard wireless extensions
*
* Version : 20 17.2.06
*
* Authors : Jean Tourrilhes - HPL
* Copyright (c) 1997-2006 Jean Tourrilhes, All Rights Reserved.
*/#ifndef _LINUX_WIRELESS_H
# nl wireless.h | head
1 /*
2 * This file define a set of standard wireless extensions
3 *
4 * Version : 20 17.2.06
5 *
6 * Authors : Jean Tourrilhes - HPL
7 * Copyright (c) 1997-2006 Jean Tourrilhes, All Rights Reserved.
8 */9 #ifndef _LINUX_WIRELESS_H - mkfifo is the coolest one. Sure you know how to create a pipeline piping the output of grep to less or maybe even perl. But do you know how to make two commands communicate through a named pipe?First let me create the pipe and start writing to it:

Then read from it:

- ldd, want to know which Linux thread library java is linked to?
# ldd /usr/java/jre1.5.0_11/bin/java
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00bd4000)
libdl.so.2 => /lib/libdl.so.2 (0x00b87000)
libc.so.6 => /lib/tls/libc.so.6 (0x00a5a000)
/lib/ld-linux.so.2 (0x00a3c000)
- col, want to save man pages as plain text?
# PAGER=cat
# man less | col -b > less.txt
- xmlwf, need to know if a XML document is well formed? (A configuration file maybe..)
# curl -s 'http://bashcurescancer.com' > bcc.html
# xmlwf bcc.html
# perl -i -pe 's@<br/>@<br>@g' bcc.html
# xmlwf bcc.html
bcc.html:104:2: mismatched tag
- lsof lists open files. You can do all kinds of cool things with this. Like find which ports are open:
Note: OpenBSD 101 pointed out that “lsof -i TCP” a better way to obtain this same information. Thanks!Or find the number of open files a user has. Very important for running big applications like Oracle, DB2, or WebSphere:
# lsof | grep TCP
portmap 2587 rpc 4u IPv4 5544 TCP *:sunrpc (LISTEN)
rpc.statd 2606 root 6u IPv4 5585 TCP *:668 (LISTEN)
sshd 2788 root 3u IPv6 5991 TCP *:ssh (LISTEN)
sendmail 2843 root 4u IPv4 6160 TCP badhd:smtp (LISTEN)
vsftpd 9337 root 3u IPv4 34949 TCP *:ftp (LISTEN)
cupsd 16459 root 0u IPv4 41061 TCP badhd:ipp (LISTEN)
sshd 16892 root 3u IPv6 61003 TCP badhd.mshome.net:ssh->kontiki.mshome.net:4661 (ESTABLISHED)
# lsof | grep ' root ' | awk '{print $NF}' | sort | uniq | wc -l
179
Note: an anonymous commenter pointed out that you can replace sort | uniq with “sort -u”. This is true, I forgot about the -u flag. Thanks!


October 21st, 2007 at 11:17 pm
[…] publishing 10 Linux commands you’ve never used I was the benefactor of much feedback as to how I could have used the commands better. Which is […]
October 24th, 2007 at 5:10 am
[…] available to you at the Linux shell prompt. Here are 10 that you will have never heard of or used.read more | digg […]
October 29th, 2007 at 11:10 am
[…] read more | digg story […]
November 2nd, 2007 at 5:31 am
I am familiar with seven of them, Any way good JOB
November 11th, 2007 at 1:08 am
great list. my personal favorites are ldd and pstree. those commands saved my butt a few times. ldd in particular, is useful to resolve dependencies.
November 12th, 2007 at 1:08 pm
[…] read more | digg story […]
November 15th, 2007 at 10:00 pm
[…] 10 Linux commands you’ve never used […]
December 3rd, 2007 at 3:00 pm
I had already used some of them. In fact some years ago, I had to program a server, that served files from a directory, through a named pipe, to different clients at the same time, and all in bash!
I bet I can add more usually not know commands: rpl (I used to have my own sed script for this) and lshw (I got surprised to find that few people know this great one, which is better than lspci, lsusb…).
Good article and blog!
December 17th, 2007 at 5:32 pm
netstat is also very useful for getting a list of open ports. I typically use netstat -ntpl
December 31st, 2007 at 3:22 am
[…] 10 Linux commands you’ve never used (tags: 10 linux list 2007 applications lists opensource mac apps article articles osx os reference bash blog research blogs code resource resources computer script server computers development cool shell sysadmin tech education tips todo firefox:bookmarks fun training toread tutorial tricks geek guide hacking hacks Ubuntu tutorials unix howto imported useful utilities internet learning web commands) […]
January 1st, 2008 at 4:41 am
Ever used “tee” [ http://en.wikipedia.org/wiki/Tee_(Unix) ]? Not too many people I know have used it but is awesome when you need to view the output of a process and copy it to a file as well.
January 9th, 2008 at 11:02 am
Available on linux only: watch
watch ‘ls -lt /tmp |head’
for example, shows whether your program is generating temp files, updating every 2 seconds.
January 15th, 2008 at 11:40 pm
Your article might be more aptly titled, “10 More Linux Command I’m Not Interested In Using.” This command-line stuff is SO twentieth-century–Linux needs to get with it already.
[Cue obligatory flames]
January 31st, 2008 at 2:24 am
[…] 10 Linux commands you’ve never used (tags: linux commands) […]
January 31st, 2008 at 3:13 am
Flame war comming now…
Well, no actually, you NEED to master the shell if you really want to be able to administer a Linux/unix server /system
February 4th, 2008 at 12:16 pm
lsof -u root
is possible, too (last example)
February 7th, 2008 at 4:34 am
[…] 10 Linux commands you’ve never used (tags: bash shell) […]
February 10th, 2008 at 3:11 am
Do you know of pushd and popd? pushd is the same in usage as cd except it keeps track of where you’ve been in a stack and if you want to go backwards in that list (stack) then you just popd.
I’m actually pretty noob but a friend of mine who is a whiz showed me that one and another whiz friend of mine didn’t know of it so I thought I’d pass it on. Actually I knew 3 from this list: pstree, pgrep and split. So I’m not feeling like such a noob anymore… I’ve been using Ubuntu after abandoning windoze98 almost 2 years ago. I use pgrep with pkill a lot. I love how with this stuff you will get frustrated and take a lot of time to solve a problem - same as windoze. But after you’ve solved it you feel a lot smarter because you now understand computers more completely and will be fast at the same problem the next time. Unlike windoze which teaches you almost nothing.
February 10th, 2008 at 7:20 pm
csplit to split by regex
February 12th, 2008 at 12:19 pm
@rusl,
I rarely use pushd and popd, but I think that increased usage of them, would likely be beneficial. I’ll keep that in mind!
@U N Owen,
That is a good suggestion!
February 17th, 2008 at 12:41 pm
Hmm.. we need 10 windows commands too
March 11th, 2008 at 12:50 pm
[…] a bad list of “10 Linux Commands You’ve Never Used“. Obviously most of these are application to any nix variant, so are worth checking […]
March 11th, 2008 at 9:19 pm
Good list, although I use 8 of them on an almost daily basis (5 of them multiple times per day). We use Samba at work, so lsof is a must to unlock locked XP files.
March 12th, 2008 at 12:31 pm
people awk can grep!!
output | awk’/search/ { print $2 }’
lsof is an expensive command you may want to use its options to limit its search instead of grep’ing full output
ie.. lsof -iTCP:port -a -u root (show me root process on this TCP:port)
March 12th, 2008 at 1:01 pm
josh,
Thanks for your comment! I will update these examples to reflect this. Should have awhile ago…
Yes, I wrote about this at a later date: Do it better with awk 2.
Also, as I noted after #10, the -i option is a better use.
Brock
March 17th, 2008 at 5:52 pm
[…] 10 Linux commands youve never used (tags: linuxcommands) […]
April 3rd, 2008 at 8:58 am
`cat -n` also gives numbers to the lines, but definitely nl is a shorter command
April 7th, 2008 at 3:32 am
Great info. I was familiar with just two of them.
Tina
April 9th, 2008 at 1:24 pm
Note that “cat -n” also adds line numbers, although there aren’t as many options as nl.
Also, bc correctly interprets running out of input as “quit”, so there’s no need to add it explicitly:
$ echo -e '2+2\nsqrt(9)' | bc
4
3
April 10th, 2008 at 7:33 am
@John Lowry:
“watch” is indeed linux only, but you can just use while & sleep anywhere else:
while true; do
ls -lt /tmp | head
sleep 2
done
April 18th, 2008 at 11:32 pm
these are very useful for us keep on listing the commands