Linux/Unix

Posts about using Linux and Unix

Print Out A Random Futurama Quote

25th June 2008 - 2 minutes read time

If you sent a curl request to the slashdot.org server you get back a random Futurama quote contained within the header information. The following curl command:

curl -Is slashdot.org

The commands supplied are I and s. I causes only the header of the file to be shown and s stops curl printing out anything. This returns the following headers:

Bash Fork Bomb And The Cure

24th June 2008 - 3 minutes read time

A fork bomb is a simple bit of shell code that, once run, will soon fill all available memory and fork space with itself. Here is the code, and remember, don't try this at home!

$ :(){ :|:& };:

To explain what is going on we need to cut this code into sections. The first thing we do is refine a function called ":", which accepts no parameters.

$ :(){};

We then get this function to run itself recursively and also to run another version of itself in the background, this creates another fork of the program.

$ :|:&

Finally we start it all off with the first function call.

Delete File By inode Reference

9th May 2008 - 1 minute read time

If you want to delete a file that you can't type in the name of either because the name is long and complicated, or because it is difficult to type in without causing a syntax error then here is the solution.

You first need to find the inode reference of the file. This can be done by using the command ls -li. The start of each line has a number that is specific to that file. You could use the command ls -i , but the output is a little confusing.

To delete the file use the find command with the flag -inum, followed by a pipe into the rm (remove file) command like the following.

find . -inum 916618 | xargs rm

The xargs bit is used to pass a list of the files found from the find command to the rm command.

View Directory List After Entering

11th April 2008 - 1 minute read time

When navigating the file structure in Unix/Linux environments you will often find yourself typing cd to change the directory and then immediately typing ls to see the contents of the directory.

It is possible to run ls automatically every time you run cd by adding the following commands to your .bashrc file.

Simple Trick To Run Last Command As Sudo

10th April 2008 - 1 minute read time

You can often forget what you are not running as a super user, so if you type in a command that you can't run with your current set of privileges it will tell give you a permission denied response.

An alternative is to use the !! command to run the last command in the .bash_history. Use this with the sudo command to run the last command as a super user.

  1. > command
  2. Permission denied
  3.  
  4. > sudo !!

The PHP User On Linux

5th January 2008 - 2 minutes read time

Reading or writing a file using PHP is quite a common practice, but it can often fall cause programs to fall flat on their face if the proper user privileges are not in place. Although this is not a problem on Windows machines due to the lack of a proper security model, but on Linux machines you need to make sure your scripts can run with the correct permissions.

First you must determine what the name of the user and group is. On OS X the default is "www" for both user and group. If you are using Apache then the user and group information is kept in the http.conf file. Look for a couple of lines that look like this, this is the default settings for Apache 2.2.