Wednesday, March 11, 2009

Project: Building An All-Text Linux Workstation - Part 4

In this installment, we will explore web browsing and install a couple of packages to help with file management.

A Text Web Browser?

Yes, there are such things. In fact there are several available for Linux. Our Debian workstation has one installed by default. Called w3m, it is a full featured browser that operates in text mode. So what can you do with it? Well, we won't be watching YouTube with it, that's for sure, but many well written web sites (especially those designed to follow acceptable standards of accessibility) will render just fine. We can try it out:

me@linuxbox:~$ w3m linuxcommand.org

and after a few seconds we will see this:

The arrow keys will navigate, and the tab key will advance from link to link. Shift-h will bring up the help screens and shift-b will perform a "back" function (this will get you out of help too). Press the q key to quit w3m. The program can do tabbed browsing, render tables and has a number of command line tricks. This blog renders fine too, so you can now follow along directly on our all-text system.

Unfortunately, there is a bug that prevents w3m from using the mouse on the console to help with navigation. Fortunately, there are other browsers that you can install. See the link at the end of this article.

Automatically Mounting USB Devices

If we insert a USB flash drive into our system, we will see a kernel message appear on the screen. This is because the kernel sends its messages to the console in the hopes that an ever-vigilant operator (that's you) is paying attention. However this message means very little as it only announces the fact that the kernel has detected a device attached to the USP port. It does not mean that the system has done anything useful, like mounting the device. We could manually mount the device, that that is a nuisance.

To solve this problem we will install a package called usbmount that can automatically mount USB devices. We can do this using aptitude. Just search for the "usbmount" package and install it. We described the process in installment 3.

After the package is installed, we must modify its configuration file to allow support for VFAT file systems, the type most often used on USB drives. As a precaution, usbmount does not enable VFAT since the kernel does not fully support the "sync" mount option on VFAT file systems. Normally, usbmount allows USB devices to removed without unmounting. It does this by keeping file systems "synchronized," that is, it immediately writes changes to the device versus waiting to consolidate multiple write for improved performance. With VFAT enabled, the user must issue a sync command before removing a USB VFAT device.

After the package is installed, we need to (as root) edit the /etc/usbmount/usbmount.conf file and change the following two lines:

FILESYSTEMS="ext2 ext3"

to:

FILESYSTEMS="ext2 ext3 vfat"

and:

FS_MOUNTOPTIONS=""

to:

FS_MOUNTOPTIONS="-fstype=vfat,gid=floppy,dmask=0007,fmask=0117"

After the configuration file is modified, usbmount will automatically mount VFAT devices. You will find the mount point in the /media directory. When a flash drive is inserted we can verify the mount using df:

me@linuxbox:~$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda1             18856292    980140  16918280   6% /
tmpfs                   160096         0    160096   0% /lib/init/rw
udev                     10240        88     10152   1% /dev
tmpfs                   160096         0    160096   0% /dev/shm
/dev/sda1                15560      5944      9616  39% /media/usb0
and we see that the drive has been mounted on /media/usb0. Just remember to use the sync command before removing the device, or really bad things may happen to the drive:

me@linuxbox:~$ sync

Midnight Commander

The last package we will install in this episode is Midnight Commander, a text based file manager. Using aptitude, install the mc package and the following additional packages that are recommended: arj, bzip2, odt2txt, unzip, and zip. If you prefer, you can use apt-get to install the packages as the mc package is a little hard to find using aptitude:

linuxbox:~# apt-get install mc arj bzip2 odt2txt unzip zip

After mc is installed we can fire it up:

me@linuxbox:~$ mc

and the following screen will appear:


The numbered blocks along the bottom of the screen correspond to the function keys, F1-F10 and permit access to many of the programs functions and it has a lot of them! Unlike w3m, the mouse is well supported by mc.

That's all for this installment. While you're waiting for Part 5, study Midnight Commander. It has a help function and a man page. That should keep you busy for a while! Also, if you are interested in other text-based web browsers, check out the Text Mode Browser Roundup from Linux Journal.

Further Reading

Other installments in this series: 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Monday, March 9, 2009

Dvorak Likes Linux

I never thought that I would live long enough to see it, but John C. Dvorak, professional curmudgeon likes Ubuntu!

Thursday, March 5, 2009

Interview With Steve Bourne, Creator Of sh

Computerworld has a very interesting interview with Steve Bourne, the author of sh (the ancestor of bash) where he talks about the history of the Unix shell. A good read for you Unix history buffs out there.

Wednesday, March 4, 2009

Project: Building An All-Text Linux Workstation - Part 3

In this installment we'll learn how to navigate the text environment and install our first packages.

If you have gotten through parts 1 and 2 of our series, you now have a sparkling new Linux system that displays -- a prompt! But if you think it only displays one prompt, you'd be wrong, as we shall soon see.

Let's fire up our system and log in again as the root user.

One of the commands I often use is locate, which rapidly searches a small database of files installed on the system. locate is installed on our system but when we try to use it we get the following message:

linuxbox:~# locate foo
locate: can not open `/var/lib/mlocate/mlocate.db': No such file or directory

This message appears when you try to use the locate command before the database is created. Normally the database is rebuilt each night by a cron job, but unless you let the machine run overnight, the database will never get built. We'll fix this problem in a little bit, but to solve the problem in the meantime, we'll run the database update program manually:

linuxbox:~# updatedb

After it completes, locate should start to work. If you are unfamiliar with this wonderful utility, now is a good time to look at its man page.

If we enter the command:

linuxbox:~# locate foo

We will get back a long list of filenames containing the string "foo." Go ahead and do this. Notice how the list scrolls off the top of the screen. Next, type shift-PageUp and notice how we are able to scroll up the list. Shift-PageDown scrolls downward.

The terminal screen is only 80 characters wide but sometimes a command will output lines wider than 80 characters. This will usually cause the text to wrap but in some rare instances it will actually go off the edge of the screen. In these cases, you can scroll the screen sideways by using the shift-right arrow and shift-left arrow.

To see the next keyboard trick, type Alt-F2 and you will see a new login prompt. Actually you are seeing another virtual terminal you can log into. Go ahead and log in using your ordinary user name and password. Now try the who command:

me@linuxbox ~$ who
root tty1         2009-03-04 13:49
me   tty2         2009-03-04 14:28


As we can see, we have two users logged in. Type Alt-F3 and we'll see another virtual terminal. In fact, on our system, Alt-F1 through F6 provide separate terminals we can use. You can use Alt-right and left arrows to rapidly cycle through them.

Wouldn't It Be Great If The Mouse Worked?

Let's go back to the first terminal session where root is logged in by typing Alt-F1. Then start up the aptitude program:

linuxbox:~# aptitude

aptitude is a fancy character based way to install packages on Debian and other Debian-based distributions. It has many features and is a handy way to manage packages on our system. The apt-get program is also available. aptitude features a multi-pane screen:



It took me a few minutes to figure out the user interface, but after installing a few packages with it, I figured it out. We're going to use aptitude to install a couple of packages. We'll use its search feature to help us out. Type / and a search prompt should appear. Enter "anacron" and it should find the package in its database.



You can use the tab key to toggle between the two display panes. With the package name highlighted, press the + key to mark the package for installation. Next, let's do another search, this time for "gpm". If it does not find it the first time, type "n" to search for the next occurrence. Repeat until it finds a package named simply gpm. This use of / (search) and n (next) is the same as the less program. Again, type + to mark the package for installation.

With our two packages selected, it's time to install them. We do this by typing "g" (for "go".) aptitude will display a summary of the actions it is about to take and by pressing "g" a second time, the installation will commence. When installing gpm for the first you will see an error message about being unable to shut down the daemon. This may be safely ignored.

When the aptitude screen returns, type "q" to quit.

We have now installed anacron, which will make sure that periodic tasks (like running updatedb) take place even if the machine is not run continuously. We also installed gpm which should make the mouse work. Some of the programs that we will install in upcoming installments can use a mouse, but its most useful feature is that we can now use the mouse to copy and paste text, just like we can on the X display. The only difference is that the right button is used to paste rather than the middle button.

You can terminate your extra terminal sessions by typing "exit" and root can shut down the machine by:

linuxbox:~# shutdown -h now

That's all for today. See you again soon!

Further Reading

Other installments in this series: 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Monday, March 2, 2009

Linuxcommand.org Terminal Screenshot Colour Scheme

I recently received this email from inquisitive reader Dermot:
Hi

I was going through your website http://linuxcommand.org tonight and find it really easy to follow how the commands and descriptions are laid out. I have a question about the screenshots you use.

The terminal screenshots have a black background, with "[me@llinuxbox me}$" in green and the commands to be run in white. How did you get this colour scheme? Ive been asking on Ubuntuforums and other forums, as it would really make the lines on which you enter commands stand out against the output results of those commands.

Please get back to me if you get a chance.

Thanks

Dermot
Ireland

Thanks Dermot for taking the time to write. The "screen shots" you refer to aren't actually screen shots at all. They're implemented in hand-coded HTML and CSS, but you can create the same effect on your own system. Here's how:

The contents of your prompt are defined in an shell variable called PS1. You can examine its contents like this:

me@linuxbox ~$ echo $PS1
${debian_chroot:+($debian_chroot)}\u@\h:\w\$

This example is from an Ubuntu system. Other distributions will be different.

To set the colors, first use the Edit -> Current Profile dialog in gnome-terminal to set the color scheme to "White on black":

Next, you need to add some ANSI color codes to the prompt string contained in PS1. To change the prompt to green and then back to its original colors (so that subsequent text will remain white), you need to change the prompt string to this:

\033[0;32m${debian_chroot:+($debian_chroot)}\u@\h:\w\$\[\033[0m\]

You can test your prompt by setting the PS1 variable this way:

me@linuxbox ~$ PS1="\033[0;32m${debian_chroot:+($debian_chroot)}\u@\h:\w\$\[\033[0m\] "

After you are satisfied with the new prompt design, you can make it permanent by adding these two lines to your .bashrc file:

PS1="\033[0;32m${debian_chroot:+($debian_chroot)}\u@\h:\w\$\[\033[0m\] "
export PS1

Hope this helps!

You can read more about configuring the prompt at the Linux Documentation Project. They have an excellent HOWTO document entitled:

The Bash-Prompt HOWTO