linux

Creating Mac OSX Aliases

Adding an alias to your system is a good way of saving time when remembering complex commands. You can reduce a command down to a quick two letter command that is easy to remember.

The alias command can be used to assign an alias on the fly. You can create an alias to 'ls -lah' by typing in the following into the command line.

alias ll="ls -lah"

Now, when you type 'll' (i.e. two lower case L's) you will actually run the command 'ls -la'.

Or you might want to do more complex things like running your selenium server.

alias selenium-server="java -jar ~/Development/selenium-server-standalone-2.25.0.jar"

To remove an alias you can use the unalias command to remove an alias from your system.

Happy Birthday Bash Script

Following on from the PHP script to print happy birthday I wanted do the same in a bash script. I don't really use bash for much more than stringing together commands so I had to figure out how to do loops and if statements using the simple bash syntax. I also wanted to pass the name of the person as an argument, rather than hard code it into the script. This is what I came up with.

#!/bin/bash

output=''
for i in {1..4}
do
  output=$output"Happy birthday "

  if [ $i -eq 3 ]
  then
    output=$output"dear $1\n"
  else
    output=$output"to you\n"
  fi
done
 
echo -e $output

Save the file as happy.sh or similar and run it in the following way (Name is the argument that we pass to the script).

$ ./happy.sh Name

Find The Size Of Files And Directories In Linux With The du Command

The du (or 'disk usage') command is a Linux command that can print a list of the files within a directory including their sizes and even summarize this information. It is useful if you want to see how large a group of files is and provides more information about directories than the ls command does.

Using du within a directory will show you the size (in bytes) of all files and directories under that directory, including the size of the current directory. To make du produce more readable results just use the -h flag to make the file sizes into a human readable format. You can also use the -c flag to produce a grand total of all of the sizes found, and the -s flag to display only a total. The -a flag can be used to display all files as well as directories, leave this out to just display directories.

Remove SVN Files From Source In Linux

There might be a couple of reasons why you would want to do this. Perhaps the repository has been checked out instead of exported, or maybe the repository doesn't exist any more. A couple of strategies exist remove all SVN files from a set of directories in Linux. You can either use the rm command directly and pass in a find command using grave accent quotes (key to left of '1').

rm -rf `find . -type d -name .svn`

Or you can pass the output of the find command to the xargs command, which calls the rm command.

find . -type d -iname ".svn" -print0 | xargs -0 rm -rf

You can even use the -exec flag of the find command to run the rm command.

find . -type d -iname ".svn" -exec rm -rf {} \;

Using xclip To Copy Output From The Command Line In Linux

When copying the standard output from within a terminal I often push it to a file using the "command > file" syntax. The trouble is that I then end up with a file that I have to open in order to get the output, and I often forget to delete the file once finished. This is especially annoying when I just want to paste some debug output into a help topic or similar. The solution to this is to use xclip to store the output in the xclipboard instead of a file. This is essentially the function of xclip, it allows access to a clipboard that you can store anything in.

A good example of this in use is when pasting the output of php -i into the amazing xdebug tailored instillation instructions. When you print this to the terminal you get pages of output. To push this into xclip instead just pipe it like this.

Installing A Realtek Wireless Card On OpenSuSE Linux 11

I've been using my Medion Akoya E1222 netbook for about a year now and I still think it's an awesome little machine. Recently, I decided to swap from Ubuntu to another Linux distro and have been experimenting with Fedora, JoliOS, PuppyLinux before finally going for OpenSuSE. The only problem I had was figuring out how to get the wireless card working.

I had a little bit of trouble tracking down this information, so I thought I would put it here both for future reference and for anyone else looking for the same information. This is mainly specific for my netbook and particular distribution, but it might help others with the same sort of problems.

The first thing you need to do is find out if your system can actually see the wireless card. This can be done using the lspci command, which in my version of SuSE needed to be called directly from its location in the sbin directory.

Running Commands In The Background In Linux

A useful technique to know about when using Linux is to run commands in the background. Sometimes certain commands can either take a while (like copying a large file) or will simply take over the terminal window when run. For example, lets say that you open a file in gedit, you might use the following command.

gedit file.txt

Doing this will open the file in gedit but will not allow you to do anything in the terminal window until you close gedit. To open the file but still keep the terminal window active use the & symbol at the end of the command. This will run the proceeding command in the background.

gedit file.txt&

To run a file copy in the background do the following.

cp file.txt file.txt.bak&

Note that this command shouldn't be used for all commands, especially those that produce some form of output. For example, running the following command

Using !$ To Use Last Parameter

Much like using Alt+. to print out last parameter you can also use !$ to use the last parameter from the previous command. Here is a simple example.

# cd ..
# cd !$

In this example we are moving up a directory and then doing the same action again, the !$ is a short cut to get hold of the ... This is more useful when doing things with longer parameters like directory or file names. For example here we are creating a directory and then moving into that same directory.

# mkdir /www/htdocs/directory/
# cd !$

Raising Skinny Elephants Is Utterly Boring

This might sound odd, but this is a mnemonic that helps you remember a sequence of letters that you can enter when your Linux system is locked. This is a last ditch attempt to get things up and running again and should only be used if all else fails and the only other thing that you can do it pull the plug.

If you have also tried pressing Ctrl+Alt+backspace and this does nothing then you can try using the key sequence Raising Skinny Elephants Is Utterly Boring.

Hold down the left Alt key and the SysRq key (found on the print screen button) and press each letter in turn. Make sure that you give a little time between keystrokes.

  • r
  • s
  • e
  • i
  • u
  • b

Here is a description of what you are doing.

Use Alt+. To Print Out Last Parameter

A handy trick when using a Unix/Linux system is to repeat the last parameter from the previous line. Lets say that you typed in the following line to move a file to another directory.

$ mv file.txt /usr/local/

To then move into that directory you can just type cd and Alt+. to copy in the last parameter used in the last line. This will put the following on the command line.

$ cd /usr/local/

You can press Alt+. multiple times to go back through your parameter history. Note that it only records the last parameter used for each line. So for the example above, if you pressed Alt+. twice you would get the last parameter of whatever command you executed before moving the file.