Nifty commands

So, helping someone with an issue earlier (amarok had crashed and they couldn’t kill it properly), I told them to issue the following command

ps x | awk '/amarok/ {print $1}' | xargs kill -9

Now, this is a command I use a lot to kill programs that are being evil (generally, I use it to kill evolution!)

But the comment came back “That’s nifty!”

So I’ve got to ask, what are your favourite “nifty” commands? and what do they do?

<edit> So far, within 5 mins of posting this, I’ve had 2 people ask why I don’t just use killall

mez@apathy:~$ ps x -ocommand | grep [e]vo
evolution
/usr/lib/evolution/evolution-data-server-1.12 <snip>
/usr/lib/evolution/2.12/evolution-exchange-storage <snip>

Tags: , ,

22 Responses to “Nifty commands”

  1. Dan Says:

    I’m a big fan of the `pidof` command and the killall command myself. They make life much easier than gifuckingantic shell constructs with tons of pipes for no reason.

  2. Florob Says:

    Why don’t you just do
    killall -9 amarok
    ?

    What I have to come to appreciate a lot is replacing with sed (very helpful when e.g. dist-upgrading):
    sed -i s/foo/bar/ file

  3. Mez Says:

    Ah, but, that wouldn’t catch “ruby /usr/share/apps/amarok/scripts/score_default/score_default.rb” (which was what was causing the issues)

    or say for example, with evolution

    mez@apathy:~$ ps x | grep evo
     6906 ?        Sl     3:06 evolution
     6918 ?        Sl     0:00 /usr/lib/evolution/evolution-data-server-1.12 
     6938 ?        Sl     0:05 /usr/lib/evolution/2.12/evolution-exchange-storage 
    
  4. Diego Flameeyes Pettenò Says:

    pkill is your friend then :)

  5. Koko Says:

    CTRL+R in terminal! <- history of previous commands.

    This one totally rocks! Ctrl+R , type “oxy” and you have: svn checkout /http://sdjghshkr.adjgh/ oxygen icons trunk

    It’s better than “cd ..” and “cd -” or “cd ~” for browsing folders.

  6. Mez Says:

    Why use cd ~ when you can just cd?

  7. Lee Says:

    “pkill -9 amarok” is kind of nice. It’s in the debian psutils package, I think. There’s also a pgrep, which does something a lot like ps | grep.

  8. ubuntu user Says:

    Here’s something useful I learned recently. To print the man page for a command to pdf with nice formatting using an already-configured cups-pdf printer you can try:

    man -t | lpr -P pdf

    It’s the -t option that produces the nice formatting.

  9. Dennis K. Says:

    evolution –force-shutdown

  10. Jeff Schroeder Says:

    In re: to your original ps command…
    pkill -u $USER -9 amarok”

    Also take a look at pgrep and the man pages.

    “tload” Ascii system load graph (installed by default normally)

    “lsof +c 15 | awk ‘{print $1}’ | uniq -c | sort -rn | head” Sorted list of the top 15 processes with the largest number of open files

  11. mike Says:

    I’m a big fan of find myself. I use it for various things, examples:

    find . -type d -name “temp?” -exec rm -Rf {} + # or \; can be used, using + process all files on rm line, \; runs rm per file

    find . -mtime 1 -maxdepth 1 # find files and directories modified in the last day in the current directory.

    Find is just nifty in itself, I don’t use xargs much with find as many people do, just like the -exec option better.

  12. John Doe Says:

    That is unnecesarily complex, this should do the same task: killall -s 9 -r evolution

  13. Jeff Schroeder Says:

    wordpress mundged the ‘ in the awk command. make sure to use single quotes around the awk statement and it works like a charm:
    jeff@omniscience:~$ lsof +c 15 | awk ‘{print $1}’ | uniq -c | sort -rn | head
    325 epiphany
    283 liferea-bin
    250 thunderbird-bin
    248 python
    238 tomboy
    225 nautilus
    215 gnome-panel
    199 update-manager
    181 mixer_applet2
    177 update-notifier

  14. Michael R. Head Says:

    yeah, evolution –force-shutdown appears in my Alt-F2 history. There used to be a killev script, but once the –force-shutdown option was added to the evo binary, they got rid of that one.

  15. Janne Says:

    If you’re a frequent camera user it might be instructive to check what focal length you’re actually using the most. If you have “exiv2″, an exif data reader/writer installed, you can easily do this:

    exiv2 @(@(JPG)|@(jpg)) |sed -n -e “s/.*Focal length : \([0-9.]*\).*/\1/p”|sort -n|uniq -c

    You get the number of images per focal length, sorted by length. If you want a graphical representation it’s trivial to cut and paste the output to gnumeric or some other spreadsheet and graph it.

  16. Stand back, I know regular expressions at Source Guru Says:

    […] Register « Nifty commands […]

  17. Zeth Says:

    I like to combine pdftotext with grep so I can search for keywords in a bunch of PDFs.
    E.g. http://files.zeth.net/pdfgrep.txt

  18. The Linux Index » Martin Meredith: Stand back, I know regular expressions Says:

    […] after the last blog post, I was talking to Seveas and mentioned how I thought with all the nifty and useful commands coming […]

  19. litb Says:

    my commands of choice:
    # waits until the given processes (may be multiple pids) are not running anymore
    # killall -w does this too, but it waits 1second at least.
    # we don’t want to wait so long o.O .
    # NOTE: this doesn’t work on a system which uses randomized PIDs . afaik
    # linux tries to use PIDs which were not used before, so that is
    # not a problem here.
    function wait_for_pid() {
    # $@ means “$1″ “$2″ … “$n” . ( all the args given to this function )
    while ( for i in $@; do [[ -d /proc/”$i” ]] && return 0; done; return 1 ); do
    sleep 0.15s;
    done
    }

    i would be glad to know how this could be even made better!

  20. joi Says:

    http://speculation.org/garrick/kill-9.html

  21. Enver ALTIN Says:

    You can use `evolution –force-shutdown` for a graceful one.

    -HTH

  22. Kai Grossjohann Says:

    I suggest not to use killall; if you ever use it on a Solaris box, you’ll be surprised.

    pkill appears to be more portable.

Leave a Reply