linux tips

linux tips

Curly brace expansion in the Bash shell

A very handy trick using the Bash shell in Linux involves the curly braces. The Bash manual at defines brace expansion as "a mechanism by which arbitrary strings may be generated."

I use this mostly when working with files, especially making back ups of configuration files. For example, to copy /etc/X11/xorg.conf to /etc/X11/xorg.conf.backup, you could do this:

$ cp /etc/X11/xorg.conf /etc/X11/xorg.conf.backup

or you could use brace expansion

Get unique lines in file using bash

I had to take a closer look at a distributed attack on one of our web servers today. The attack only involved around 50 hosts which seemed to be testing our URL parameters for injection susceptibility. Coldfusion has some protection against SQL injection, and we take extra steps, as every programmer should, to guard against it.

After identifying the attack vector, I was able to grep the log file for the signature of the attack which was present in the URL information.

Clean Ubuntu and find large packages

While working on a wireless kiosk using Ubuntu, I had the need to shrink the Ubuntu installation. Part of creating a custom install, using remastersys, is creating a live CD iso image.

I did, of course, remove the unnecessary software and programs like the games and cd burning software (see and I ran several commands including localpurge and deborphan (see ).

Linux Tip: Compiling using multiple cores

Compiling software can be very time consuming. To speed things up, and utilize what you paid for, you can use the -j switch for make. So make -j4 bootstrap will cause make to run four jobs at one time. This speeds things up drastically and will utilize four cores.

Linux tip: making a directory with parents

Making a directory is no big deal:

$ mkdir ~/temp

But what if you have to make a bunch of directories nested? So what if I had to make ~/temp/temp1/temp2/temp3/temp4 ? Using the -p switch, for parents, the utility will create the structure for you.

$ mkdir -p ~/temp/temp1/temp2/temp3/temp4

This command will create all the directories leading down to temp4.

The watch command in Linux

A very neat command I learned about today is the watch command. This command line program executes a command periodically and shows the output in full screen. If you've ever used the top command, it's the same concept, but you can use any command.

For example, the command sudo watch cat /proc/meminfo will display the current memory information, updating it every two seconds by default, until the ctrl + c combination is pressed.

Podcast ordering in Amarok

In Amarok, under KDE 3.5, podcasts seem to be in a scrambled order. They definitely aren't in the order the author of the podcast put them in. This is a known bug and is going to be fixed in the next version of Amarok due out very soon.

As a temporary work around, I am using Firefox's ability to subscribe to XML feeds and have associated MP3 files with Amarok inside Firefox.

Using smart monitoring for drives on Ubuntu

SMART (Self-Monitoring, Analysis, and Reporting Technology) is a technology that implemented by most hard drive manufacturers that records pertinent information about the hard drive, to the hard drive, which aids in the prediction of a failure.

Linux has tools available that harvest that data, perform tests and aide in the prediction of drive failure. Normally, the bios will prompt you if SMART detects a problem with a drive, but you have to reboot in order to get that prompt and many Linux users don't reboot often.

To install the packages under (k)ubuntu, use:

Mount iso image in Linux

Using a simple mount command, you can mount an iso image and navigate the file system.

First, create the directory you want to use to access the iso. This can be any directory.

$ sudo mkdir /mnt/iso

Then, mount the iso.

$ sudo mount -o loop ~/isos/test.iso /mnt/iso

This mounts the iso file to the mount point you just made. The squiqqly line in Linux ~ means is expanded to your home directory.

Using the mail command in Linux

The mail command is a powerful command used to manage your local mail on a *nix box. I use the mail command in (k)ubuntu frequently and have root's mail forwarded to my account on my boxes.

To use mail, you'll have to install the mailx package in (k)ubuntu.

$ sudo apt-get install mailx

When you login to your linux box via the command line you might see a message such as this:

jsteelsmith@localhost-10:~$ ssh
Linux jacob-desktop 2.6.24-19-generic #1 SMP Wed Jun 18 14:43:41 UTC 2008 i686


Subscribe to RSS - linux tips