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.

  1. pgrep, instead of:

    # ps -ef | egrep '^root ' | awk '{print $2}'
    1
    2
    3
    4
    5
    20
    21
    38
    39
    ...
    You can do this:
    # pgrep -u root
    1
    2
    3
    4
    5
    20
    21
    38
    39
    ...
  2. 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
  3. 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.

    # ./sqrt
    Usage: sqrt number
    # ./sqrt 64
    8
    # ./sqrt 132112
    363
    # ./sqrt 1321121321
    36347
    Here is the script:
    # 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
  4. 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
  5. 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

  6. 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:

    mkfifo pipe; tail file > pipe

    Then read from it:

    cat pipe

  7. 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)
  8. col, want to save man pages as plain text?

    # PAGER=cat
    # man less | col -b > less.txt
  9. 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
  10. lsof lists open files. You can do all kinds of cool things with this. Like find which ports are open:

    # 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)
    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 ' 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!

31 Responses to “10 Linux commands you’ve never used”

  1. BASH Cures Cancer » Blog Archive » Improve this Script and Win $100USD Says:

    […] 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 […]

  2. Actual Technology News Blog » 10 Linux commands you've never used Says:

    […] available to you at the Linux shell prompt. Here are 10 that you will have never heard of or used.read more | digg […]

  3. Munich Unix » Blog Archive » 10 Linux commands you’ve never used Says:

    […] read more | digg story […]

  4. gg Says:

    I am familiar with seven of them, Any way good JOB

  5. Syahid Ali Says:

    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.

  6. Linux » Blog Archive » 10 Linux commands you’ve never used Says:

    […] read more | digg story […]

  7. A Penguin in the Orchard » Blog Archive » 10 Linux commands you’ve never used Says:

    […] 10 Linux commands you’ve never used […]

  8. InfoLinux Says:

    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!

  9. Jed Says:

    netstat is also very useful for getting a list of open ports. I typically use netstat -ntpl

  10. links for 2007-12-31 « Dark Corner of the Empty Head Says:

    […] 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) […]

  11. kgx Says:

    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.

  12. John Lowry Says:

    Available on linux only: watch

    watch ‘ls -lt /tmp |head’

    for example, shows whether your program is generating temp files, updating every 2 seconds.

  13. Dick Johnson Says:

    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]

  14. xocal.net v2.0 » links for 2008-01-31 Says:

    […] 10 Linux commands you’ve never used (tags: linux commands) […]

  15. Flame war Says:

    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

  16. asdf Says:

    lsof -u root

    is possible, too (last example)

  17. fcicq's del.icio.us » Blog Archive » links for 2008-02-07 Says:

    […] 10 Linux commands you’ve never used (tags: bash shell) […]

  18. rusl Says:

    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.

  19. U N Owen Says:

    csplit to split by regex

  20. admin Says:

    @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!

  21. Jackie Says:

    Hmm.. we need 10 windows commands too ;)

  22. 10 Linux Commands You Didn’t Know | Unix Trix Says:

    […] 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 […]

  23. Anita Says:

    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.

  24. josh Says:

    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)

  25. admin Says:

    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

  26. links for 2008-03-17 » blog.dreamrealm Says:

    […] 10 Linux commands youve never used (tags: linuxcommands) […]

  27. someone Says:

    `cat -n` also gives numbers to the lines, but definitely nl is a shorter command :)

  28. Tina Says:

    Great info. I was familiar with just two of them.
    Tina

  29. Edgewood Says:

    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

  30. Vincent Says:

    @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

  31. yakub pasha Says:

    these are very useful for us keep on listing the commands

Leave a Reply

If Wordpress eats your comment (shell output, loops, ex..) email the text to me.