Forkbombs and How to Prevent Them

A forkbomb is a program or script that continually creates new copies of itself, that create new copies of themselves. It’s usually a function that calls itself, and each time that function is called, it creates a new process to run the same function. You end up with thousands of processes, all creating processes themselves, with an exponential growth. Soon it takes up all the resources of your server, and prevents anything else running on it. ...

April 2, 2010 · 3 min · David Craddock

How to remove nano, vim and other editors' backup files out of a directory tree

Linux command-line editors such as nano and vim often, by default, create backup files with the prefix of “”. I.e, if I created a file called /home/david/myfile, then nano would create a backup in /home/david/myfile. Sometimes it doesn’t delete them either, so you’re left with a bunch of backup files all over the place, especially if you’re editing a lot on a directory tree full of source code. Those stray backup files make directory listings confusing, and also add unnecessary weight to the commits on source control systems such as svn, cvs, git.. etc. If you’re working on a programming team with other people, then it causes further problems and confusion, because person A’s editor can accidentally load person B’s backup file.. etc etc. Nightmare. ...

March 22, 2010 · 2 min · David Craddock

Tip for watching the completion of a large file copy

Forget the wonderful windows progress bar, and imagine I’m in the world of command-line Linux, and I want to copy a 484MB file, called VMware-server-2.0.2-203138.i386.tar.gz, from my home directory to a remote server. But I want to figure out how long it’s going to take. 1. First I can run a “du -m” command to get the total MB size of the original file: du -m /home/david/VMware-server-2.0.2-203138.i386.tar.gz I.e: david@believe:~$ du -m VMware-server-2.0.2-203138.i386.tar.gz 484 VMware-server-2.0.2-203138.i386.tar.gz ...

March 20, 2010 · 2 min · David Craddock

The Linux Root Directory, Explained

It’s helpful to know the basic filesystem on a Linux machine, to better understand where everything is supposed to go, and where you should start looking if you want to find a certain file. Everything in Linux is stored in the “root directory”. On a windows machine, that would be equivalent to C:. C: is the main folder where everything is stored. On Linux we call this the “root directory”, or simply “/”. To go up to this root directory, type: ...

March 20, 2010 · 5 min · David Craddock

Useful OSX commands for Linux users

I wrote this list to remind me, as a newcomer to OSX, how the command line differed from the Linux commandline. I thought I’d expand on it, and share it: To mount any iso: hdiutil mount sample.iso To download a file as you would using wget: curl http://ftp.heanet.ie/pub/linuxmint.com/stable/8/LinuxMint-8.iso -o linuxmint.iso -C - the -o specifies the output file (required) the -C - specifies automatically resuming if possible. To burn a bootable iso to CD, DVD or USB key: use the “diskutil” program as described in: http://forums.macrumors.com/showthread.php?t=598291 Monitor disk io utilisation.. poll once per second ...

March 19, 2010 · 1 min · David Craddock

Long Bash History Files are Great.

When I’m installing software, or doing some complicated stuff on the linux command line, which nowadays is pretty much all the time, I will sometimes want to remember exactly what I typed. Now the normal /home/david/.bash_history file is usually fine for that. Run this command, for example, and you will see the commands you typed in before you logged out of the server last time you used it: cat ~/.bash_history You can also find out what you typed in this session, ie: since you logged in, by typing this: ...

March 18, 2010 · 3 min · David Craddock

My minimal VIM config

This is the absolute minimum I do when I have to log onto a new server or shell account that I haven’t used before, that I will need to edit text files with. First I figure out whether VIM is really installed. A lot of installs, especially those based on ubuntu, ship with VI aliased to VIM, but the VIM install is usually not really VIM at all, and behaves exactly like VI but with some minor bugs fixed. This is not what I want. ...

March 18, 2010 · 2 min · David Craddock

Using the Linux command 'Watch' to test Cron jobs and more

OK, so you have added a cron job that you want to perform a routine task every day at 6am. How do you test it? You probably don’t want to spend all night waiting for it to execute, and there’s every chance that when it does execute, you won’t be able to find out whether it is executing properly - the task might take 30 minutes to run, for example. So every time you debug it and want to test it again, you have to wait until 6am the following day. ...

March 13, 2010 · 5 min · David Craddock

Changing the default "From:" email address for emails sent via PHP on Linux

I’ve had to solve this problem a couple of times at least, and it’s quite a common task, so I thought I’d document it here. When you send emails to users of your site through using the PHP mail() function, they will sometimes turn up in the mailbox of customers of your site with the following from address: From: Root <root@apache.ecommercecompany.com> This makes absolutely no sense to your customers, and often they will think it is spam and delete it. Often, the decision will be made for them by their web mail host, such as hotmail.com or googlemail.com, and they will never even see the email. You don’t want this to happen. ...

March 10, 2010 · 2 min · David Craddock

Shell scripts for converting between Unix and Windows text file formats

I’ve been using these shell scripts I wrote to convert between unix and windows text file formats. They seem to work well without any problems. If you put them in the /usr/sbin/ directory, they will be accessible on the path of the linux admin account root. /usr/sbin/unix2win `#!/bin/bash Converts a unix text file to a windows text file. usage: unix2win requirements: sed version 4.2 or later, check with sed –version sed -i -e ’s/$/r/’ $1 ` ...

March 9, 2010 · 1 min · David Craddock