Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Wednesday, 30 January 2013

Copy and rename multiple files

What do you do on Linux when you want to rename, copy or move many files together in the same way, e.g. replacing all files named "donkey01.jpg" as "horse01.jpg" ? There is plenty of GUI utilities, but sometimes a quick and cheap shell hack is needed. Here you go: the magics of sed and shell scripting in a one liner.

for i in `ls *`; do cp $i `echo $i | sed "s/search/replace/g"`; done

From here.

Tuesday, 27 November 2012

Killing all processes that match a given string

If you want to kill all processes matching a given executable, you can easily use killall:

killall -9 my_executable

But what if you don't want to kill processes based on an executable name, but rather on some argument name, or something else? That is, all processes that match some string?

You can. Here is the trick:

kill -9 $(ps aux | grep -v grep | grep my_process | awk '{print $2}') 

(originally from here)

Friday, 12 October 2012

Using wget to get multiple files from http servers

The Unix wget utility support globbing, but only when pointed to Unix FTP servers. So this could work:

wget ftp://something.com/*.jpg

but this will not

wget http://something.com/*.jpg

What do you do when you want to do this for an http server? A common case is where you have numbers for example, like

http://something.com/0.jpg
http://something.com/1.jpg
http://something.com/2.jpg

etc.

In this case the solution is

wget http://something.com/{0,1,2,3,4,5,6,7,8,9}.jpg

In this case the command will be repeated for all numbers and you get all 10 images in one go.

Monday, 14 May 2012

Search your installed Debian packages by repository

If (like me in this exact moment) you have a mess of a Debian (Ubuntu, Mint) system, and you want to know what packages you have installed from what branch / origin (stable, testing, unstable, experimental, backports) you can use Aptitude for that:


aptitude search '?narrow(~i, ~Abackports)'
 
Substitute to "backports" the repo you want to list, and you will obtain a fancy package list.

The ?narrow option tells aptitude to list only the installed packages. If you remove it, you'll get all packages you can install from that branch.

Another way is to install apt-show-versions and then use:


apt-show-versions -b | grep experimental


(again, substitute to "experimental" the branch you're interested in)

Thursday, 11 August 2011

Recursive find

Sometimes you don't have locate , or you want just to find recursively below your current directory. Here is a handy alias:

alias fn='find . -name':
Example usage: $ fn "page*.htm"

Tip from Joe Grossberg.

Friday, 18 February 2011

OCR of scanned PDFs in Linux

It seems there is still no quick-and-ready solution, but found a few interesting scripts.

This script based on Tesseract worked well for me. It requires to have Tesseract and ghostscript installed, and returns a number of ASCII text files from the PDF. Given that the OCR engine is the same used by Google, you can be assured it works pretty well.

A bit less comfy solution can be found on this Linux.com article, with some shell script based on Tesseract as well.

Another solution using other engines.

It seems also there is a potentially elegant GUI solution by means of OCRFeeder, but I still haven't tried it. I'll let you know how it works, for now I just bookmark these links.

Tuesday, 8 February 2011

Install True Type fonts on Ubuntu in three steps

It's very easy:

1)Create a .fonts subdirectory in your home directory
cd ~
mkdir .fonts

2)Move the .ttf file in the .fonts directory
mv myfont.ttf ~/.fonts

3)Refresh the font cache
sudo fc-cache -f -v

And your font should be ready to be used.
Credits to Detector Pro -I streamlined the process a bit, being comfortable with the command line.

Saturday, 8 May 2010

udevinfo and udevadm

If you have ever tried to write UDEV rules , say, to get your external hard drive to mount at your preferred custom mount point, you will have found necessary to use the little utility udevinfo.

Recently this utility has been superseded by udevadm. However there is a way to get the old udevinfo output back with udevadm:

udevadm info -a -p $(udevadm info -q path -n /dev/your-device)

and you will have the same output you would have had with udevinfo. Very useful! Credits to Unlikely Source for the hack.

Saturday, 10 May 2008

Create a .tar.gz archive

Ok, this is admittedly really noobish. But it's something I always forget. While the tar -xzvf spell for unpacking archives is well known, only seldomly I need to create archives.

However, here's the magic:

tar -pczf name_of_archive.tar.gz /path/to/directory

That's more a reminder for me...

Thursday, 1 May 2008

Find and delete broken symlinks

The Gentoo guide to switch from tetex to texlive contains a little command line gem. It allows you to look for broken/dangling symbolic links and delete them interactively:


find /usr/bin -type l ! -xtype f ! -xtype d -ok rm -f {} \;

Saturday, 29 December 2007

Copying whole partitions preserving hidden files and attributes

How do you easily and coherently copy a whole large and complex directory, preserving attribution, hidden files etc? Good old cp -a could not be enough in this case (hidden files would be skipped), and maybe you don't want to use dd (e.g. you could like to move a ReiserFS partition to an ext3 partition). The trick is hidden in the Debian tips , but can be applied to any Linux (and probably Unix) distribution. Since I got crazy yesterday trying to find it again, after using it to move partitions from my old hard drive to a new one, I repost it here:
find . -depth -print0 | cpio --null --sparse -pvd /new/directory
That's it. A 1:1 copy of your filesystem hierarchy is deposited in the new directory. It saved my day.

Thursday, 1 November 2007

A Linux user fights Mac OS X Leopard. Days 2-4

In the previous post, I wrote about my very first (3 hours) impressions on using Mac OS X, comparing it with the operating system I mostly used before, that is Linux.

Some day has passed, I used Leopard a bit more, and now it's time for some new random thought.

Of dock and stacks. I begin to have problems with the dock. I figured out that nothing like an application menu is easily available on this thing. I tried to "emulate" that by using stacks, but this does not really work. Stacks are an OS X Leopard innovation. Basically, if you drop a folder on the dock, this will show up as single icon. Clicking on it , you see the content of the folder, stacked. See here for example.

There are several problems with stacks. First, the stack icon is basically a superimposition of individual icons of things in the stack. A very bad idea. For example, my Documents folder is represented in the dock by a .zip dull icon, because the first file OS X sees is a zip file. Of course, I cannot customize the icon appearance. Nothing in that icon tells me it's my Documents folder.

Compare it with KDE standard behaviour, where you can place additional menus at will on your panel. Kubuntu uses it to have a standard "Places" menu where you have links to your home folder, the network computers, storage media and other users folder. No Finder clicking needed. See this screenshot for example. Also XFCE implements that. In this, for usability, Linux desktop environments beat OS X hands down.

So, to have an application stack, you have to put your applications in a given folder, then drag this folder on the dock, and you'll find yourself with a crippled menu-like thing that doesn't allow for menu hierarchy, with incomprehensible icons. Don't like that, and the neat visual effects make me cry even more: instead of an awesome-looking menu-like thing, we have a crippled thing that just looks awesome.

The Dock seems also subtly buggy ; it lost application links on me at least a couple of times. Hope it gets fixed soon.

I like the fact that an active application is evidenced on the dock, instead of taking space of an application bar. It seems a bit inconsistent from time to time (now Firefox for example brought another icon of itself on the dock, with a bright spot underneath, instead of adding the spot on the icon I launched it from), but maybe it's me not understanding its logic.

Finder. It seems me and this thing cannot be friends. It's such a retarded file manager that makes Windows Explorer look cool. Tree view is available, but why can only you switch from tree view to icon view to the three-panes view? In Konqueror I have available a tree view of my folders on the left, like the Bookmarks panel of a browser, and then the main icon view of the currently selected folder. So you can have nice previews and you can easily navigate the tree, all in once. Windows too, if I remember correctly, allows this.

If there is a free, decent OS X file manager let me know.

Open source applications. I mostly use open source software, and it is of course repackaged for Mac OS X too. Sadly, OS X looks a bit of a neglected platform for open source, which is very strange given its Unix foundations. I installed Firefox, Thunderbird, VLC, FreeCiv, Celestia, Inkscape, NeoOffice, aMSN and Gimp. Mixed results. Firefox and Thunderbird seem to work perfectly. Java and Flash support is installed by default, which is a good good thing. aMSN also integrates nicely, and is visually much better on OS X than on Linux.

GTK applications, like GIMP and Inkscape, are another story. They work fine, provided the X server is on, but using a GTK app on OS X is tiring. I am accustomed to mix and match look-n-feels on Linux, so aestethics is not the problem. The problem is the mixmatch of two paradigms: the "menu-bar-always-on-top" of native OS X and the "menu-bar-is-in-the-window" of almost all other operating systems. Mixing widget appearance is fine; mixing usability paradigms is an hell.

I think Apple should give the users the possibility to configure OS X so that the menu follows the application. I don't know if it does; it can be some advanced setting, but it has to be made easy. OS X forces its paradigms on the user and applications, disregarding anything away from this paradigm. It would also be nice if other operating systems can follow the OS X paradigm at user will, but the default is not the OS X one, so it's Apple that has do to that first. Good to think different, bad to force everyone to think like you.

I noticed also that OS X packages are left behind in terms of stability and being up to date. Celestia and GIMP crashed on me quite often -GIMP regularly when I try to draw. The GIMP binary is a 2.4 release candidate -no 2.4 final binary is available. Freeciv 2.1.0 is unavailable for OS X, and 2.0.9 doesn't start at all -it shows the initial screen, then silently dies. OpenOffice is unavailable unless in the reincarnation NeoOffice, which is behind at version 2.2. On Linux, most of these packages are rock solid and up to date. I will have to try MacPorts soon, that probably can improve the situation, but it's not an easy install and it's OK only for power users.

Don't know who's in fault here, but the situation could improve.

iTunes. I wanted to play an mp3 folder from a DVD-r. So I inserted the disk and dragged the folder on iTunes. That bitch, instead of simply playing, copied all the mp3s in the Music folder, reorganized them on her way, and only after begun playing. Didn't. Ask. Me. Anything. This is an insult -I never asked you to copy a file, let alone to copy in a location I didn't told you and to reorganize them as you (not me) find pleasurable!! It's incredible such a totalitarian approach is default behaviour. iTunes should at the very least have asked if I wanted to copy-and-reorganize folders, or not. I didn't touch it anymore. I hope someone can point me to a better music player.

Terminal. Didn't use it a lot, but it's OK. Its default appearance is terrible, but it can be customized and has true ARGB transparency. It also has tabs, which are a really useful thing. It seems thing are not color-coded as much as in Linux, which is a bit sad, but not essential.

Spaces. Spaces is Mac OS X Leopard implementation of virtual desktops. Virtual desktops are something I simply cannot live without. Unix had it from decades, and I'm extremly happy to see them implemented by default and easily activable. Only little drawback is they lack a clickable preview on the menu bar or the dock. Virtual desktops lose a bit of usability if you can't see what's in them. Again, KDE (but also GNOME) here lead the pack.

Network management. As far as I can see, wireless and DHCP connections Just Work. Good.

Suspend. I still haven't understood what happens when I close the lid. Does it go to suspend-to-ram or suspend-to-disk? Can I choose? Can I freely bring the laptop with me without shutting it down? Probably it's just me not being accustomed to laptops, but OS X should give me a better control on this. However it works seamlessly, something that I doubt is on Linux.

Login screen. I haven't figured out a way to change the login screen background. Also, when choosing the picture login avatar, OS X doesn't rescale it if it's larger than the default, but allows only you to zoom it in. A minor detail, however.

General impressions. This review was much on the negative side, but it's a simple selection effect. What I had to say in detail was on the negative. There is a positive side, of course. OS X is a usable and decent workplace, and beats standard Windows most of time. Aestethically, it's really pleasant and day to day work can be done. The problem for me is that there is not much to be enthusiast about. If the OS X interface was one of the Linux desktop managers, it would probably be considered cool but not really superior.

What really I dislike of OS X is its "totalitarian" approach. Do you want a different skin for the window manager, an application menu, a different menu layout? Too bad, you can't. If you like the OS X way, all is fine. If you don't, Apple simply does not care. I know that third-party applications can overcome most of these limitation, but it's simply wrong that I have to look for third party, unsupported apps to do things that every other OS allows me to do by default.

Linux surely is still behind in terms of overall usability. Hardware support has incredibly improved but it's still flaky here and there, there are inconsistencies, things are not as perfectly polished as they should be. And Linux must be installed by hand, thus putting users in the realm of the unknown. However, from the interface productivity and usability point of view, Apple in my opinion has no more the high ground. They are more or less equal; strenghts and weaknesses being differently distributed but quantitatively not much different. It seems to me that now Apple has as much to learn from open source desktops as open source desktops learned from it.

Tuesday, 30 October 2007

A Linux user fights Mac OS X Leopard. Day 1

So, I finally have a laptop. I bought a brand new Macbook Pro Santa Rosa yesterday morning. I choose it as a laptop mainly for the hardware combination: decent screen width (15"), low weight (2.4 kg), good battery life (4-5 hours). Definitely not a cheap gadget, but once in a lifetime...

This Macbook is my first meeting with the Mac OS world. I have used DOS and Windows machines like everyone, and it's almost four years I use almost exclusively Linux on the desktop, both at home and in my laboratory (Gentoo at home, Kubuntu at work). So for me the Mac OS is the new thing, but I guess my perspective is a bit different from the usual Windows-to-Mac transition.

To be honest, I plan to install Gentoo Linux on the Macbook quite soon. No prejudice against Mac OS, but I like to run an open source operating system, and the customizability of Linux cannot be surpassed. But I want to dip my toes in Mac OS.

I fired up the feline beast and used it for about three hours yesterday. These are just my very very first impressions, so take them for what they are. Biased, ignorant, emotion-loaded.

0) Boot time. Incredibly fast. Being accustomed to minute-long Linux boots, I'm very impressed.

1) The graphics. Shiny, smooth and slick as much as possible. Everyone knows that. I like the icon design, even if it's maybe a bit too detailed -maybe equally good but less baroque icons could be made. On the contrary, the folders icons are so minimal to be almost useless. The "special effects" are light (nothing as fancy as CompizFusion can get) but well made, and Exposé is something really useful, as I found using Beryl/CompizFusion. A pleasure for the eye.

2) Finder. I have some beginner perplexity on the usability of Mac OS X Finder. To me, the finder sounds like a retarded concept. I understand it must be something like a desktop manager mixed with a file manager, but worse. For example, I expect that right clicking on the desktop brings up a menu. Ok, let's forget right mouse buttons in the Mac world. Apple+click. Well, it does nothing. To get to what we would call the desktop menu, you need to get to the Finder. Why?

The file managing part also looks quite terrible me. The Itunes-like preview is cool but pretty useless. The system seems at first sight to go to every length possible to hide what for me is a basic information: filesystem hierarchy. I want to see where is everything. I want control. I want to reconstruct paths of my things blindly. OS X seems to mangle this all. I am sure that applications are not in a folder like my music and pictures are. So, why putting them together? What's gained by doing that? And I'm sure the "Pictures", "Documents" and "Music" folders are somewhere in my filesystem hierarchy, they are not dangling. Why don't you show me where they are attached?

Actually, you can see it all clicking on "Macintosh HD". Still looks like a bit dumbed down information, but at least now I know there's a Unix-like hiearchy with Users/Massimo/ being my home folder. Good! That's what I like. Why don't you allow to show me a damn old good folder hierarchy tree on the left, Mr.Finder, instead of "Places"?

Problem is, I am accustomed with Konqueror. Konqueror, the default KDE file manager, is probably one of the applications that hooked me definitely to Linux. It's incredibly easy to use, customizable and powerful at the same time. It's one of that open source miracles that should be advertised much more. I am accustomed to switch between filesystem hierarchy tree view, list view, my storage media, Windows connections etc. all at one mouse click. I can split the Konqueror window in two, with two completely different locations together, or I can use tabs. Or both. I have immediate access to ftp, sftp and smb connections. I'm not sure Finder manages half of this all; I'll look for it.

3) Accessing to applications. Mac OS X , as far as I can see now, has no concept of an application menu. You get the dock, or you have to look for the application in the Applications folder, which mixes everything together. What if there are things that you don't want to see everyday in the dock, but you want to find easily when needed? Probably there's a way out, but I've still not found it (nor read about it).

4) Application menus. This is a well known Mac idiosyncracy: application menu bar is on the top of the screen. Period. I suspect there's some usability theory behind that, and after fifteen minutes it becomes indeed not so bad. Unless you have a little window on the bottom right of the screen and you need a menu on the top left, in which case you have to move the mouse in diagonal through more than half screen. Why, oh why?

5) Installing applications. I still believe that THE way to install applications on a system is using a package manager. Luckly Mac OS X has at least three available, so this will be no problem. However, I didn't dislike the .dmg approach too much. Download a disk image, copy application to Application folder, voilà. Easy enough (and much better than Windows), but I would like a lot to have an official package manager. Imagine looking for "Office" on a search bar, finding office apps you like (maybe even ones you would have never suspected about!), clicking on them, and voilà -they get downloaded from the net and installed. On Linux, this is commonplace. For proprietary apps, a PayPal button could be easily added.

6) Safari. Used it the time needed to download and install Firefox, so I can't really comment on it.

This is enough now, but I'd like to hear about opinions by Mac users and Linux users too. I'm sure I'm missing a lot of the picture, so I'm open for advices!

Thursday, 19 July 2007

Installing the new Oxygen icons under KDE 3

KDE 4 is coming, and it is bringing a truckload of improvements and goodies. Among these, there is the brand-new Oxygen icon theme. Oxygen will be the default icon theme of KDE 4 and it is going to be damn good. Look at the preview to have an idea by yourself.

With a strange move for an open source project, KDE 4 is quite secretive about the new icon theme. The plan is to present the whole suite together, keeping Oxygen as a "novelty", so, even if Oxygen is being currently developed and most icons are already done, there are no official downloads provided for Oxygen. Moreover, the KDE 4 developers somehow "discourage" using Oxygen on a KDE 3 system.

However, Oxygen is open content (Creative Commons Attributions-Share Alike and LGPLv3 dual-licensed) and it is online in the KDE 4 SVN repository. So nothing legally prevents you to download and try the current Oxygen development version on your system.

It is not straightforward to obtain a KDE 3 -installable theme from the KDE 4 SVN repository, however someone (as often happens in the OSS world) has done the dirty work for you. After a bit of googling I found a handy script that automatically downloads the latest revision of Oxygen icons, converts them (using Inkscape for that purpose, so check you have it installed) and packages it as a theme (that is a single .tar.bz2 file) in your home directory.

The script is a bit slow, but works: basically just download the file from the webpage above, unzip it, open a shell, enter in the directory, run ./install.sh as a normal user and wait. When it has finished, just look for the Control Center in your KDE menu and go through Appearance and Themes --> Icons --> Install new theme and open the oxygen-icon-theme.tar.bz2 file in your home directory created by the script. Voilà, theme installed.

How does it looks? Really professional and cool. I must admit however that it can look somehow out-of-place on a common KDE 3 system, so probably KDE 4 developers are right -to fully experience Oxygen, better wait KDE 4 at the end of the year. However, here is some screenshot for your pleasure: 1 , 2 , 3 , 4

Saturday, 24 March 2007

Bygfoot: an open source soccer manager game

I've never been a lot into gaming, so the relative lack of good Linux games never bothered me much. The only game I really loved was Civilization, and Freeciv is, for me, a perfect replacement for it. Sport games were usually the ones I disliked more. Nevertheless I remember myself playing a game called "Soccer Manager" on a DOS box when I was 10-12 years old. I enjoyed it, since it was a purely micromanagement thing. In that game you played the character of a football manager that decides the team formation, sells and buys players looking at their age and skills, maintains the stadium etc. You don't actively play football, like in "Sensible Soccer": you manage the football team.



It came to me as a nice surprise when I only recently discovered Bygfoot, a free soccer management game, was available on Linux. I decided to give it a spin and come back to my childhood memories.


Free Image Hosting at www.ImageShack.us

Bygfoot is actively maintained and has recently hit release 2.1, with new features added at each release. It is based on the GTK toolkit. You can find precompiled packages for Bygfoot for Windows as well for most Linux distributions and there are official FreeBSD ports. The game has one playing as a manager of a football team, training the players, buying and selling them, contracting loans, maintaining the stadium, and so on. Teams can be promoted or relegated, and a player can be fired if their skills are not up to scratch.



I played some days with Bygfoot and my reactions are mixed. There is a lot of positive to say. The GUI is overall very well thought, elegant and simple; anyone that already played a soccer manager should master most basic game's controls in less than half an hour. I've tested versions from 1.8 to 2.1 on different machines and I'm pleased with the visible fast progress of development, both in terms of functionality and user interface. The number of teams available is enormous, thanks to many contributors, albeit the names are not 100% real due to "copyright problems" (I don't really understand that one, since it baffles my mind on how someone can have copyright on the names of players in a soccer team, but so says Wikipedia). The latest versions of the game are quite stable (the 1.9.2 version available on Ubuntu Dapper had a horrible memory leak, however) and at a casual look seem quite bug-free and fast.


Free Image Hosting at www.ImageShack.us

On the other hand, the gaming experience is nice but not impressive. It must be said that Bygfoot is eerily addictive, at least at the beginning, and the game is well thought up to be both playable and challenging at first. However the game itself becomes repetitive too rapidly. There are not that much options to gain money apart from improving the stadium and waiting for people to come in or selling your players. Exchanging players with other teams, as far as I've seen, is not possible (if I'm wrong, tell me please!). The idea of the "Youth academy" is nice, but players coming from there take an excruciatingly long time to improve their skills as to be significant players. The recent addition of betting is nice but doesn't really spice up the game. More often than not the game is a repetitive "play match-play match-play match-substitute injured player-play match" with little or no user interaction.


Overall, Bygfoot is a good free soccer manager makes for a fun and well done casual game to play here and there, let's say, in breaks at work. However it is still not at the point to be a real challenge to spend your night with.

Wednesday, 14 March 2007

Small Linux tip: Companion controllers and USB hardware

Browsing the Gentoo forums I stumbled on an odd problem with one of these "easy-but-who-the-hell-would-have-thought-of-this" nasty solutions.


Symptoms: You connect a USB hardware (e.g. an USB scanner) and nothing happens. It seems it is not recognized. But you know that your scanner/printer/whatever works and it should work with Linux! (This often happens with SiS motherboards)


Solution: Check you have OHCI/UHCI support enabled. If not, enable it. Try modprobe ohci-hcd and/or modprobe uhci-hcd as root. If even this doesn't work, chances are you compiled your kernel by yourself (most distros should include OHCI): check in your kernel config you have OHCI enabled.


Rationale: The problem is that a USB 2.0 controller card is often coupled to OHCI (or sometimes UHCI) controllers, to deal with low or full speed devices, while the EHCI controller keeps the high speed devices for himself. The hardware switches controllers depending on the attached device. So if you only have EHCI drivers and your scanner switches to the OHCI/UHCI controller, there won't be a driver for that controller -and therefore, your PC cannot communicate with what's attached there. You can read the full explanation here, look for "USB 1.1. "Companion Controllers"".

Wednesday, 7 March 2007

Polar heart rate monitors on Linux

Do geeks keep fit? Well, if you are a self-trainer, or you simply like to keep fit, you may find a heart rate monitor useful. Personal heart rate monitors often are thought to output their data on a Windows machine. Can you keep fit on Linux?



The answer is: yes, but it's not that easy (but hey, mind exercise is still exercise!). In general, it seems the best supported heart rate monitors are the ones from Polar, so I will focus on that ones.



Polar Viewer is a Polar (and Ciclosport, actually) heart rate monitor application that has been now integrated into Sports Tracker from the version 2.0. It seems the best choice for heart rate monitoring on Linux: it supports a quite wide range of Polar models, is integrated in a self-training application, it's currently updated and looks polished. As the Sports Tracker page says, "you can easily create diagrams and statistics for specific time ranges and sport types." and, if you feel coding, "all the application data is stored in XML files. So it should be easy to access it with other tools or to write importers and exporters for other applications.". Note: it depends on Mono. Another GTK application similar to Polar Viewer is Polar Scope.



On the KDE side of things, I found a small application, KPersonalTrainer, that can help you sync with your Polar monitor. According to the description:


KPersonalTrainer was developed to keep track of data collected by a heart rate monitor like the Polar Watches, or just any other watch.


When you have added an exercise information is saved in a file and presented in a table. A calender is shown to give you an overview of the finished exercises.


KPersonalTrainer also has an option, Weekly Reports, where you can keep track of your progress.


This first version of the program has all the basic functions, and more advanced functions are planned for future releases, for example show diagrams of different data.

. Unfortunately, the last update is of more than a year ago, but I guess you can poke the developer if you need an update.



I found other attempts at using Polar heart rate monitors under Linux. They seem to be decidedly more hackish, but may be nonetheless interesting. A program to decode the sound data recorded by Polar S410 has been written: however keep in mind that it is a .tar.gz that needs to be compiled by hand and comes from the 2004. A Linux software for the Polar s710 that works via the serial IR interface exists and is updated. The author of this program also owns the (admittedly not so crowded) polar-linux forum.



Last but not least: if you are really into the geeky thing, why don't you build a Linux-based heart rate monitor yourself? You only need a Linux PC, a soundcard and some circuit bending skills. Circuit schematics are ready for you to download, software is provided. Happy hacking.

Create a Linux ram disk to use with an application

If you have plenty of RAM memory, it may be useful to create a temporary RAM disk to use for fast file read-write of an application. Often guides tell you how to create an initial ram disk for the Linux boot, but what about building a ramdisk for everyday use?



It's matter of just four commands. First, create the device:

mknod -m 660 /dev/ram b 1 1

Then, give the dimension you want to the new ramdisk, let's say, 4k. You do it by filling it with the right amount of zeroes:
dd if=/dev/zero of=/dev/ram bs=1k count=4k

Then it's just matter of creating your mountpoint:

mkdir /mnt/ramdisk

and mounting it as an ext2:
mount -t ext2 /dev/ram /mnt/ramdisk
That's it.

Monday, 5 March 2007

Busybox: a lifesaver for your Linux system

Sometimes it just happens. You do something bad with, let's say, the glibc, and suddenly you discover your command line is unusable. Even simple commands like "ls" die with a segmentation fault or similar errors. Nothing works. More often than not, chrooting won't help. Everyone would panic, unless you know you have a lifesaver: a statically linked BusyBox.


This little free software miracle contains stripped down but fully usable versions of many common UNIX utilities into a single small executable. A command line in a box. Its supported commands (actual support depends on compile configuration) include:



[, [[, addgroup, adduser, adjtimex, ar, arping, ash, awk,
basename, bbconfig, bunzip2, busybox, bzcat, cal, cat, catv,
chattr, chgrp, chmod, chown, chroot, chvt, cksum, clear, cmp,
comm, cp, cpio, crond, crontab, cut, date, dc, dd, deallocvt,
delgroup, deluser, devfsd, df, diff, dirname, dmesg, dnsd,
dos2unix, dpkg, dpkg_deb, du, dumpkmap, dumpleases, e2fsck, echo,
ed, eject, env, ether_wake, expr, fakeidentd, false, fbset,
fdflush, fdformat, fdisk, find, fold, free, freeramdisk, fsck,
fsck_minix, ftpget, ftpput, fuser, getopt, getty, grep, gunzip,
gzip, halt, hdparm, head, hexdump, hostid, hostname, httpd,
hwclock, id, ifconfig, ifdown, ifup, inetd, init, insmod,
install, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute,
iptunnel, kill, killall, klogd, lash, last, length, less, ln,
loadfont, loadkmap, logger, login, logname, logread, losetup, ls,
lsattr, lsmod, lzmacat, makedevs, md5sum, mdev, mesg, mkdir,
mke2fs, mkfifo, mkfs_minix, mknod, mkswap, mktemp, modprobe,
more, mount, mountpoint, mt, mv, nameif, nc, netstat, nice,
nohup, nslookup, od, openvt, passwd, patch, pidof, ping, ping6,
pivot_root, poweroff, printenv, printf, ps, pwd, rdate, readlink,
readprofile, realpath, reboot, renice, reset, rm, rmdir, rmmod,
route, rpm, rpm2cpio, run_parts, runlevel, rx, sed, seq, setarch,
setconsole, setkeycodes, setlogcons, setsid, sha1sum, sleep,
sort, start_stop_daemon, stat, strings, stty, su, sulogin, sum,
swapoff, swapon, switch_root, sync, sysctl, syslogd, tail, tar,
tee, telnet, telnetd, test, tftp, time, top, touch, tr,
traceroute, true, tty, tune2fs, udhcpc, udhcpd, umount, uname,
uncompress, uniq, unix2dos, unlzma, unzip, uptime, usleep,
uudecode, uuencode, vconfig, vi, vlock, watch, watchdog, wc,
wget, which, who, whoami, xargs, yes, zcat, zcip


Quite impressive, isn't it? You can call busybox in various ways. The simplest is calling busybox directly with the wanted command as an argument:



busybox ls /

for example. But you can also enter a busybox shell by typing:



busybox sh

This starts a barebones shell that gives you access to all busybox commands, and allows you to have a working command line (On Gentoo Linux, you can have the same by calling /bin/bb, that is called the "rescue shell" in the docs). Another possibility is to symlink commands to the busybox binary. So, if /bin/ls is a symlink pointing to busybox, busybox will know the symlink called and execute ls. This of course has little sense when rescuing a system, but it is often used when busybox is the actual shell of an embedded or very lightweight Linux system.


Having a static busybox (static is important: you want it to be resilient to borked libraries) installed could make the difference between crying in front of a dead Linux that needs to be reinstalled and being able to grin while telling again the geeky story about how you happily rescued your system. Install it now, before it's too late.

Merge PDF files on Linux

Sometimes you need to merge PDF files made by someone else in a single file together. Your Windows or Mac user fellows will do probably by using Adobe Acrobat or the like. On Linux you don't need the Adobe software (although you can have it if you like). You can do it by the command line -it's Linux after all, isn't it?


The first method is by using convert , directly from the ImageMagick toolkit. You probably already have this one installed on your favourite Linux distribution; if not, almost every known Linux distribution has a package for it. Even if you don't need to edit PDF files you should have it, it is a wonderful swiss army knife for command line image processing. The syntax for merging PDF files is simple:


convert file1.pdf file2.pdf file3.pdf out.pdf


(that is, the last file name is the output file name). This usually works quite correctly, but 1)it is slow 2)I found sometimes has issues with image resolution. So I looked for another solution, and I found pdftk. The name stands for "PDF ToolKit", and really it is. It is a free (open source under the GNU GPL), wonderful command line utility that with a bit of magic allows you to manage PDF files from the command line. It works on Linux, Windows and Mac. pdftk can merge PDF documents, split PDF pages into a new document, rotate PDF Pages or Documents, decrypt and encrypt, fill PDF forms, apply a background watermark or a foreground stamp, burst a PDF Document into single pages... whatever.


The syntax for merging with pdftk is almost as simple:


pdftk file1.pdf file2.pdf file3.pdf cat output out.pdf

You just need to add the magic "cat output" between the input pdfs and the output file name. In comparison with convert, it is truly fast and in my experience gives better results. And it may come handy for when I have to work with PDF files in other ways. Also, KDE users may find nice PDF Concat, a Kommander script that acts as a simple pdftk frontend to merge PDFs.