A chronological documentation test project, nothing serious, really!

28 Oct 2007 Rename files in folder

Oneliner to rename files/directories. It converts ” ” into “_” and the characters to lower-case.

$> perl -e 'while(< *>) { $old=$_; s/ +/_/g; rename($old,lc($_)); }'

To limit it to a single filetype use it this way and replace ”.doc” with whatever you like.

$> perl -e 'while(< *.doc>) { $old=$_; s/ +/_/g; rename($old,lc($_)); }'


Posted by

28 Oct 2007 Information about shutdowns and reboots

A easy way to get information about shutdowns and reboots is to run the command

last reboot


last -x | grep down


Posted by

28 Oct 2007 Updating WordPress using a bash script

If you have shell access to your webserver this script can be used to upgrade your WordPress installation to the latest version quickly. Always remeber to backup your database and installation files before running it!

Do change the bold text to reflect your WordPress Internet address before you run the script.

echo Updating WordPress located in $CURDIR
echo 1. Downloading latest WordPress install file.
wget -q
echo 2.  Unpacking downloaded file.
tar zxf latest.tar.gz
cd wordpress/
echo 3.  Replacing old files with the unpacked ones.
tar cf - . | (cd $CURDIR; tar xf -)
echo 4.  Update the WordPress installation.
wget -q -O - ${SITE}/wp-admin/upgrade.php?step=1> /dev/null
echo 5.  Removing the WordPress file downloaded recently.
rm -f ../latest.tar.gz
echo 6.  WordPress is now upgraded.

Tags: , , ,

Posted by

25 Oct 2007 Using TCP Wrappers to deny daemon access in specified hours

By doing the following you can deny certain daemons to be available in specified hours by using hosts.allow and hosts.deny.

In my example I will be using the vsftpd daemon by adding


in /etc/vsftpd.conf.

Make sure that your private network has access all the time by adding this in /etc/hosts.allow

vsftpd: 192.168.0.

Enables access to the whole subnet.

Next you create a /etc/cron.d/vsftpd file

0 16 * * 1-5 root perl -i -p -e s/innhold//ig /etc/hosts.deny
0 8 * * 1-5 root echo "vsfdpt:ALL >> /etc/hosts.deny

Reload the cron daemon and you’re good to go.

The above example will deny all addresses, except those specified in hosts.allow, between 08:00 and 16:00 Monday to Friday and clear the block at other times.

Tags: ,

Posted by

25 Oct 2007 Recursivly find and edit files in place

This is a simple oneliner to replace words inline using perl :)

# for i in `find ./ -name foo` ; { perl -p -i -e “s/oldword/newword/g” $i ;}

You’ll need bash and perl.

Tags: ,

Posted by