Archive for the ‘Linux’ Category
Batch Renaming Using sed
I was reorganizing my music library and decided to change the naming convention I’ve used. This task is just asking to be automated. Since the filename change could be described using regular expression, I looked for a way to use sed for the renaming process.
The files I had, had the following pattern as filename ARTIST – SONG – TRACK – ALBUM
James Brown - I Got You (I Feel Good).ogg - 01 - Classic James Brown
I wanted to rename it to ARTIST – ALBUM – TRACK – NAME
James Brown - Classic James Brown - 01 - I Got You (I Feel Good).ogg
Describing the change as a sed program is easy:
s/\(.*\) - \(.*\) - \(.*\) - \(.*\).ogg/\1 - \4 - \3 - \2.ogg/
Now all that has to be done is to pass each filename to mv and pass it again after it went through the sed script. This could be done like this:
for i in *; do mv "$i" "`echo $i | sed "s/\(.*\) - \(.*\) - \(.*\) - \(.*\).ogg/\1 - \4 - \3 - \2.ogg/"`"; done
The important part is the
`echo $i | sed "s/\(.*\) - \(.*\) - \(.*\) - \(.*\).ogg/\1 - \4 - \3 - \2.ogg/"`
which pipes the filename to sed and returns it as an argument for mv.
To see what renaming will be done one can alter a bit the above command, and get
for i in *; do echo "$i" "->" "`echo $i | sed "s/\(.*\) - \(.*\) - \(.*\) - \(.*\).ogg/\1 - \4 - \3 - \2.ogg/"`"; done
While will effectively print a list of lines of the form oldname -> newname.
Of course this technique isn’t limited to the renaming I’ve done. By changing the pattern given to sed, one can do any kind of renaming that can be described as a regular expression replacement. Also one can change the globbing (the *) in the for loop to operate only on specific files, that match a given pattern, in the directory instead of all of them.
Kernel Configuration for acpid Issue
I’ve installed acpid on my system some time ago (Gentoo package: sys-power/acpid. However each time I tried to start it it complained:
acpid: can't open /proc/acpi/event: No such file or directory
Apparently acpid requires you to enable ACPI_PROC_EVENT, which in it’s labels states “Deprecated /proc/acpi/event support”. I really wonder why such tool only support the deprecated way to receive the ACPI events.
NVRM: not using NVAGP, kernel was compiled with GART_IOMMU support
For the past several weeks I had a strange problem. Sometimes when I booted my computer, it would refuse to start the X server and would give the following error in dmesg:
NVRM: not using NVAGP, kernel was compiled with GART_IOMMU support!!
NVRM: failed to allocate stack!
The weird thing about it is that normally if I rebooted the computer it would magically work again. So this error only showed up once-in a while and seemed to disappear at will. Today, it happened again, so I decided to fix it.
Read the rest of this entry »
rzip vs. bzip2 – A short comparison
I decided to benchmark rzip against bzip for my backup needs. The benchmark was performed on a 89M tar archive of a directory which I regularly backup using my Amazon S3 backup script. The directory contains mostly LaTeX, PDF and Open Office files, so this benchmark may reflect very different results than what you will get if you will test it on other kinds of files.
Read the rest of this entry »
usb 1-4: device descriptor read/64, error -71
When I try to connect my Sansa Clip MP3 player to the linux box I see the following error in dmesg:
usb 1-4: device descriptor read/64, error -71
and the device recognition fails. The player’s battery gets reloaded but I can’t mount it and transfer songs.
Read the rest of this entry »
Start Trac on Startup – Init.d Script for tracd
As part of a server move, I went on to reinstall Trac. I’ve tried to install it as FastCGI but I failed to configure the clean URLs properly. I got the clean URLs to work if the user access them, but Trac insisted on addeing trac.fcgi to the beginning of every link it generated. So I’ve decided to use the Trac standalone server, tracd.
The next problem I faced was how to start the Trac automatically upon startup. The solution was to use an init.d script for stating Trac. After some searching, I didn’t find an init.d script for tracd that were satisfactory (mostly poorly written). So I went on an wrote my own init.d script for tracd.
Read the rest of this entry »
Backup Directories To Amazon S3 Script
This is a small script I wrote today, to automate my backups, which I do on Amazon S3. This is fairly short, yet useful bash script that utilize the s3cmd to do the actual sending of the files.
Read the rest of this entry »
Activating Guarddog Settings on Startup
Like many Linux users, I use Guarddog as a frontend to my iptables firewall. At some point, I noticed that Guarddog started acting strangely. Every time I restarted my computer, all internet traffic was blocked (both in and out). The only way to fix this situation was to open Guarddog and press “Apply” (without doing any changes). While it was annoying, it didn’t bother me much because I used to restart my computer about once a month. But few days ago, I decided to solve this problem once and for all.
Read the rest of this entry »
Delete Unversioned Files Under SVN
Sometimes svn switch fails because unversion files exist in the working copy, and the need to erase them comes up. This is also true when updating to an old revision (usually one that misses directories that exist in the head revision), doing some work (like compiling), and then trying to update back to the head revision. Subversion (SVN) will fail complaining that directories/files already exist.
Read the rest of this entry »
Creating Local SVN Repository (Home Repository)
In this tutorial I will explain how to create a local Subversion (SVN) repository, intended for a single user. I assume that you already know the benefits of keeping track of old revision of projects or important documents such as a resume or a thesis you have been writing. Subversion offers you a very convenient yet strong method to do so, and the easiest way to do so with Subversion (SVN) is to create a local, home, repository intended for a single user – you.
Read the rest of this entry »