The ls, du, and sort Commands, How to Get the LILO Prompt Back

The ls command allows file listings to be displayed in a variety of ways. Commonly used options are -a (does not hide dot.files), -l (long/verbose listing format, includes file attributes and sizes), and -color (displays files/directories in different colors depending on attributes). Type man ls to get a more complete listing of options.


How can I change the way files are displayed by default in a directory listing?

The ls command allows file listings to be displayed in a variety of ways. Commonly used options are -a (does not hide dot.files), -l (long/verbose listing format, includes file attributes and sizes), and -color (displays files/directories in different colors depending on attributes). Type man ls to get a more complete listing of options.

One of the easiest ways that you can set default attributes for ls is to set up a shell alias. I’ll use bash for the example here. Try adding the following line to the file .bashrc in your home directory.

alias ls = ls -a -color

You can also type this command in the current shell to make the alias effective immediately (until you close your shell).

The lines in the .bashrc file are run every time you begin an interactive shell, ensuring that this alias is reset automatically.


I have a Perl script that will not run. Executing it results in a bash: ./script.pl: No such file or directory error. The file exists and is executable. Why won’t it work?

Executable scripts may use the first line of the script to tell the shell which pro-gram to run in order to execute the script. It always exists as the first line and looks something like:


If the listed program exists, it will be used to interpret the rest of the script. If it does not exist, you will see the No such file or directory error. This is not exclusive to Perl, also being used in most shell scripts.

It is not uncommon to see #!/bin/ sh or #!/bin/ bash as the first line in a script. The fix for this is generally easy. Perl may exist in a different place on your system than on the system of the author. Typing which perl will give the location to your own Perl binary location. Changing the first line of the script to reflect the location on your system should fix the problem.


I have installed a program, but when trying to execute it, I get an “error in loading shared libraries…no such file or directory” message. I have located the file in question. Why would I get this error?

Some programs use something called “dynamic libraries” to store pieces of code that may also be used by other programs. When a program is executed the operating system may look for these libraries in certain predefined places. If the library is not found, an error such as the one you described above will occur.

If you get this error, one of two things is true. Either you don’t have the library at all or you have the library and Linux just can’t find it for some reason. If you don’t have the library, you’ll just need to get it. Otherwise, some simple modifications will most likely solve the problem.

One way to fix things is to ensure that files are installed to standard library directories, including /lib and /usr/lib. Simply moving the files to these directories will confuse any package management software you use however, and should be avoided. Installation of the files to standard directories should be performed at the package management or configuration/installation level.

If you wish to leave the libraries where they are, you must first locate them, then add the directory to the linker search path.

You’ll be looking for the file displayed in the error you received. As the superuser, you can use the following command to find it.

# find / -name filename.so

When you’ve found the directory, edit your /etc/ld.so.conf file and add the directory at the end.

As the superuser, run ldconfig. This will rebuild the links and cache for the run-time linker. That’s it! Now your program should be able to find the libraries it needs to run.


I’m running out of space on my hard drive and want to target the largest directories/files on my system as deletion candidates. Are there any tools available to help with this?

There are a couple of simple commands that can help make this a very easy task. You should familiarize yourself with du and sort.

The du command is used to calculate sizes of files or whole directories. There are a variety of options, but the following lines should get you started. You will want to execute these as the superuser, or you risk getting a lot of Permission denied errors because you probably don’t have access to many directories.

To find the sizes of all root level directories and all their subdirectories:

# cd /
# du -max-depth=1

Changing the max-depth parameter allows summaries one level deeper in the directory tree:

# du -max-depth=2

Removing the max-depth parameter altogether will give the size of every file and directory in the tree. Combining du with the sort command will allow easier browsing of the output.

To view all file and directory sizes on your hard drive, sorted by size (this may take awhile):

# du | sort -nr | less

Note that removing arbitrary files can be very dangerous, especially if the files are necessary for system operation. This technique is probably best for finding users with large home directories. If you do find program files you deem unnecessary, it is certainly best to find the package that installed the file and cleanly remove the package using rpm (rpm based systems) or dpkg (deb based systems).


After installing Windows on another partition of my dual-boot machine, I no longer get the LILO prompt. How do I get it back?

During the installation of a Microsoft Windows operating system, the master boot record (MBR) is typically overwritten, and the machine will boot the new OS. Your Linux partition didn’t go anywhere, but lilo is no longer on your MBR.

The fix for this is relatively easy, as all you have to do is boot back into Linux and rerun the lilo command. If you had thought of this ahead of time, you would have made a boot floppy from Linux before you lost the ability to boot it. Lets assume, however, that you have no Linux boot floppy…

If you have another Linux system handy, you could easily make a boot disk from it using a kernel from that machine (assuming the machines have the same architecture). If you don’t, simply boot the Windows partition (you don’t really have much choice, do you?) on the affected machine. There is a very simple DOS utility called rawrite2.exe, which makes floppies out of image files. Rawrite2. exe is available from many Linux distribution Web sites, including Debian GNU/Linux (http://http.us.debian.org/debian/dists/potato/main/disks-i386/current/dosutils).

You can obtain a simple rescue floppy image from any of the Linux distribution sites as well. I’ve had success with the Debian rescue floppy, found at http://http.us.debian.org/debian/dists/potato/main/disks-i386/current/images-1.20/rescue.bin.

From the DOS command prompt, rawrite2.exe is used as follows:

C:\IMAGES\> rawrite2 -f rescue.bin -d a:

After successful writing, you’ll be armed with a Linux rescue boot disk. You’ll need to boot the kernel from this floppy and tell the kernel to load the root filesystem from your hard drive. If you don’t know which filesystem to use for the root mount, you’ll likely need to investigate through trial and error. After booting from the floppy, you’ll need to type something like the following:

LILO: linux root=/dev/hda1

The actual device will vary depending on your configuration. If your system is IDE, you’ll be mounting hda, hdb, hdc, or hdd (first controller master drive/slave drive, second controller master drive/slave drive). SCSI configurations will mount sda, sdb, etc. The number that follows the drive represents the drive partition. These number one through four for primary partitions and five and up for extended partitions.

For typical IDE configurations, the Linux root partition is usually at somewhere between hda1 and hda3. If you get the wrong root partition you’ll get an error from the kernel about how it is “unable to mount root partition.” Once you get it right, your box should boot Linux normally. You can probably get this right in a couple of tries, provided that you know your system’s basic configuration.

Once you are in Linux, the rest should be relatively easy. You’ll probably want to add an entry for the Windows partition. Add the lines shown in Listing One to your /etc/lilo.conf, substituting the drive and partition of your particular installation.

Listing One: Adding a Windows Partition Entry

other = /dev/hda4   # your DOS/Windows partition
table = /dev/hda # the current partition table
label = dos # whatever name you wish to use

Place this before or after the Linux section in lilo.conf, depending on which you wish to boot by default (first one listed). Run lilo as the superuser, and it will install itself on your MBR. A reboot should present you with the LILO: prompt once again. Use the labels listed in your lilo.conf to choose which OS to boot.

I hope this has answered your question. You can find more information at http://linuxdocs.org/HOWTOs/LILO-crash-rescue-HOWTO.html.

Drew Streib is a coder, admin, and writer with VA Linux Systems. He can be reached at tech@linux-mag.com.

Comments are closed.