Archive
Ubuntu distro info
Today I found an Ubuntu-specific command by chance called “ubuntu-distro-info“. Example:
$ ubuntu-distro-info -af Ubuntu 4.10 "Warty Warthog" Ubuntu 5.04 "Hoary Hedgehog" Ubuntu 5.10 "Breezy Badger" Ubuntu 6.06 LTS "Dapper Drake" Ubuntu 6.10 "Edgy Eft" Ubuntu 7.04 "Feisty Fawn" Ubuntu 7.10 "Gutsy Gibbon" Ubuntu 8.04 LTS "Hardy Heron" Ubuntu 8.10 "Intrepid Ibex" Ubuntu 9.04 "Jaunty Jackalope" Ubuntu 9.10 "Karmic Koala" Ubuntu 10.04 LTS "Lucid Lynx" Ubuntu 10.10 "Maverick Meerkat" Ubuntu 11.04 "Natty Narwhal" Ubuntu 11.10 "Oneiric Ocelot" Ubuntu 12.04 LTS "Precise Pangolin" Ubuntu 12.10 "Quantal Quetzal" Ubuntu 13.04 "Raring Ringtail"
This requires the “distro-info” package to be installed.
Update (20130426)
If you want info about your current distro version, use this instead:
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 13.04 Release: 13.04 Codename: raring
cpq and mvq: extensions of the Unix commands cp and mv to use a queue
Problem
You browse your hard drive(s) and you want to copy/move several files to somewhere else. If the files are big (e.g. movies), then you need to wait minutes until a copy/move operation finishes. If the files are in different folders, you cannot select them all. If you try to launch each operation in the background, your machine will get very slow since all these operations will run concurrently.
Clearly, copy/move operations should be put in a queue and the next operation should start when the previous one terminates.
Solution
Under Windows you have Total Commander (F5/F6, then F2), but how to do it under Linux? Should I use Total Commander with wine? :) Under Linux I use Midnight Commander but in MC I didn’t find this feature. There is another Norton Commander clone called Krusader that has this feature but I didn’t like it much. I prefer MC :)
So, I came up with the following solution: create two command-line scripts called “cpq” and “mvq” that work like cp and mv (actually they call cp and mv) but they put tasks in a queue. These scripts launch a daemon process if necessary that executes each copy/move operation one after the other.
The project can be found here (https://github.com/jabbalaci/Copy-Queue) where you can also find a description about its installation.
Update (20130403)
Pierre (alias Deimos) wrote about “cpq” and “mvq” in his blog in French: Copy-Queue : un manager de copie de fichiers en ligne de commande.
number
Today I found an interesting Unix command by accident. It converts numbers to English:
$ number 961428808 nine hundred sixty-one million. four hundred twenty-eight thousand. eight hundred eight.
It works with much bigger numbers too.
Set difference between two files
Problem
You have two text files, short.txt and long.txt, and long.txt contains some extra lines. Which are these lines? That is, you want to perform a set difference: L \ S.
Solution
You can do this with the “comm” command:
First, make sure that the two files are sorted. Then:
comm -23 long_sorted.txt short_sorted.txt
Example
$ cat as.txt sl-1215 sl-2112 sl-9023 sl-9029 $ $ cat bs.txt sl-1215 sl-2112 sl-9012 sl-9016 sl-9023 sl-9029 $ $ comm -23 bs.txt as.txt sl-9012 sl-9016 $
Find more examples on “comm” here (like union, etc.)
.xsession-errors can grow HUGE
Problem
Something funny happened to me today. I logged in to my desktop machine at my workplace when a warning message told me that “disk space is low”. A quick “df -h” indicated that it’s true, my HDD is at 100%! How is it possible, I should occupy no more than 30%. After hunting for 10 minutes for the guilty file/directory, it turned out that the file .xsession-errors in my HOME directory grew more than 200GB! WTF?
Solution
I removed this file and under the name .xsession-errors I put a link on /dev/null. However, after a reboot the symbolic link was gone and .xsession-errors became a regular file again. Tricky :) So I added the following lines to the end of my .bashrc file:
# .xsession-errors can grow huge... remove it
if [ ! -h $HOME/.xsession-errors ]
then
/bin/rm $HOME/.xsession-errors
ln -s /dev/null $HOME/.xsession-errors
fi
if [ ! -h $HOME/.xsession-errors.old ]
then
/bin/rm $HOME/.xsession-errors.old
ln -s /dev/null $HOME/.xsession-errors.old
fi
It verifies if .xsession-errors is a symbolic link. If not, remove it and replace it with a symbolic link.
Lock and unlock the screen from command line
Question
Is there a way to lock/unlock the screen from a script?
Answer
The answer is “yes”. Lock the screen:
gnome-screensaver-command -l
Unlock the screen:
gnome-screensaver-command -d
Demo (lock the screen, then unlock it in 5 seconds):
gnome-screensaver-command -l && sleep 5 && gnome-screensaver-command -d
Tip from here.
VLC gets stuck
Problem
On my Linux box, VLC gets stuck sometimes and only the good old “kill -9” can shoot it out. Is there a single command to kill it?
Solution
alias killvlc='kill -9 `ps ux | grep vlc | grep -v grep | tr -s " " | cut -d" " -f2`'
Screenshot from command line
This entry is based on this post.
Install:
sudo apt-get install scrot
Screenshot:
$ scrot /tmp/out.jpg
Screenshot in 5 seconds:
$ scrot -cd 5 /tmp/out.jpg