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!

54 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

  32. Max Says:

    I didn’t knew this commands but they are really helpfull for me.

  33. gorg Says:

    I’m very familiar with seven of these. That kind of scares me.

  34. Guru Says:

    Quote:
    >Jackie Says:
    >February 17th, 2008 at 12:41 pm
    >
    >Hmm.. we need 10 windows commands too

    You only need one Windows command….
    FORMAT C: /u

    Then boot with Linux.

    :-D

  35. miraj Says:

    nl does not count blank lines. But, ‘cat -n’ counts all the lines.

  36. NMC Says:

    Good list. I was familiar with 6 or 7 of them. pgrep and lsof seem to be the most useful commands I was unaware of.

  37. tom Says:

    My fav shell command…

    yes

    if you want to get fancy you can try:

    yes Why is my system pegged?

    Go ahead try it.

    Oh yeah. Don’t forget my other fav ….

    Ctrl-C

  38. Brisbane Internet Consultant Says:

    Nice list. I’m looking for a command that will redirect traffic from a local IP address and port to an external IP address and port. I belive netcat can do that sort of thing.

    eg. redirect from 192.168.0.100:161 to 204.161.7.99:161

    Any ideas?

  39. RSA training Says:

    I’m sure there’s a few commands that will do that. netcat is just one of them.

  40. Cata Says:

    Hello !
    How i make working this script?
    #!/bin/bash

    echo “Starting up”

    mpg123 /home/Catalin/Tra*
    for (( i = 1; i <= 10; i++ )) do
    echo “Sleeping 10 seconds…”
    echo $i
    sleep 1s
    done
    Thank you !

  41. alisonken1 Says:

    @Brisbane Internet Consultant:

    Netcat is used to talk to a remote machine. If you want to redirect IP:port calls, use the iptables command on your machine (for local calls only) or a linux box acting as a router (for all machines in a local network).

    $man iptables

    The syntax can be rather interesting, but you can also browse the web for specific examples.

  42. 10 Linux commands you’ve never used « Longjidin’s Kg Lengkong to Bukit Lada Says:

    [...] to bashcurescancer.com for this awesome article! Tagged with: CLI « Intercepting VoIP Calls [...]

  43. sabha Says:

    all these commands are good……..
    keep posting…….

  44. Clarkson Says:

    brilliant! some of these shall come in VERY useful: lsof ? Ya man.

  45. Kamal Says:

    col and xmlwf were new for me. Thanks.

  46. 10 comandos útiles para Linux que probablemente no conocías Says:

    [...] Vía Relacionadas Alias no es una serie de televisiónCómo mostrar el administrador de tareas en Linux al pulsar Control + Alt + SuprimirAtajos de teclado para el reproductor Listen Etiquetas: comandos, consola, Linux, Ubuntu Comentarios [...]

  47. 10 mandatos útiles para GNU/Linux. Says:

    [...] que es probable que pocos lleguen a dominar todo. En este artículo, originalmente publicado por BASH Cures Cancer y traducido y adaptado por MundoGeek.net, se muestran 10 mandatos poco conocidos y que te pudieran [...]

  48. balag Says:

    these are the really useful commands by using these command we can do great things with system

  49. senthil Says:

    NICE, very useful for me…

  50. kazumi Says:

    Interesting , very usefull.
    Thank you.

  51. 无色无味 的博客 » Blog Archive » 10个你很少使用过的Linux命令 Says:

    [...] 原文地址:http://bashcurescancer.com/10-li … uve-never-used.html Brock 老兄写了一篇文章《 你从未用过的 10 条 Linux 命令(10 Linux commands you’ve never used)》,虽然标题有点过于绝对和主观,不过文章还是不错的。其实,无论你是否听说过或者使用过这些命令,都值得我们再来重温一遍。不是吗? [...]

  52. xpert-zone Says:

    how can u check if your server is secure or not? any ideas how to do that

  53. Shantanu Oak Says:

    I have used only split (lines not file size).
    I will now try other commands. I guess tr should have been mentioned.
    I think line numbers in vim are useful too.

  54. S. Keeling Says:

    Thanks for these. There’s some here I’d never imagined existed.

    In return, I offer expand. Ever get a file that’s been mangled to death by multiple authors using various editors (some inserting hard tabs, some not)? expand will fix it. I once saved a client two weeks work (in their estimation) with that on a commandline.

Leave a Reply

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