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>
January 3rd, 2008 at 12:55 am
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.
January 3rd, 2008 at 1:03 am
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
January 3rd, 2008 at 1:04 am
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
January 3rd, 2008 at 1:08 am
pkill is your friend then
January 3rd, 2008 at 1:09 am
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.
January 3rd, 2008 at 1:13 am
Why use cd ~ when you can just cd?
January 3rd, 2008 at 1:15 am
“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.
January 3rd, 2008 at 1:19 am
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.
January 3rd, 2008 at 1:19 am
evolution –force-shutdown
January 3rd, 2008 at 1:29 am
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
January 3rd, 2008 at 1:30 am
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.
January 3rd, 2008 at 1:31 am
That is unnecesarily complex, this should do the same task: killall -s 9 -r evolution
January 3rd, 2008 at 1:35 am
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
January 3rd, 2008 at 1:48 am
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.
January 3rd, 2008 at 1:54 am
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.
January 3rd, 2008 at 2:09 am
[…] Register « Nifty commands […]
January 3rd, 2008 at 2:35 am
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
January 3rd, 2008 at 4:31 am
[…] after the last blog post, I was talking to Seveas and mentioned how I thought with all the nifty and useful commands coming […]
January 3rd, 2008 at 6:47 pm
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!
January 3rd, 2008 at 7:39 pm
http://speculation.org/garrick/kill-9.html
January 5th, 2008 at 8:48 pm
You can use `evolution –force-shutdown` for a graceful one.
-HTH
January 9th, 2008 at 4:49 pm
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.