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

Friday, February 27, 2009

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

In this episode, we will choose the Linux distribution and perform the installation.

Choosing A Distribution

After some consideration, I selected Debian 5.0 for our workstation project for three reasons:
  1. Debian is fairly simple on a conceptional level. Good, straightforward design with good documentation. It's also capable of being installed on very small machines. Its minimum memory requirement is only 44 MB.
  2. Its package repository is huge. With over 22,000 packages, we are likely to find a good selection of text based applications for our project.
  3. It just came out and I wanted to play with it ;-)
Creating Installation Media

With that decision out of the way, we next decide on the installation media. I chose the "netinst" (also called the "minimal CD") option. This is a downloadable CD image that contains a minimal base system. Additional packages are installed from the Internet. The install image is 150 MB, much smaller than the full install CDs. To use this option you must have a working network connection. If you need other installation options, take a look at the Debian Installation Guide for guidance.

You can download the installation image from here.

The last step is creating the installation CD. I will assume that your present system, Linux or otherwise is capable of that and that you know how to do it.

Installation

With our machine ready, it's time to boot up with our install CD. After the CD boots you will receive an attractive Debian splash screen listing various install options. For our purposes, select "Install", not "Graphical Install".

The installer is pretty easy to use and in most cases the default selections are fine. The arrow keys move from selection to selection as do the tab/shift-tab keys. The space bar is used to toggle the contents of check boxes.

  • When the prompt appears for disk partitioning, select "Guided - Use entire disk" and "All files in one partition".
  • At the "Set up users and passwords" screen, you will be prompted to set the password for the root account. If you have been using Ubuntu up to this point, I have to explain that Debian, like most Linux distributions has a discreet root account rather than using sudo for everything as Ubuntu does. Much of the early work we will perform on the system will require root access. Choose a root password that is both strong, and one that you can easily remember.
  • Next, you will be prompted to create your personal account. In keeping with LinuxCommand tradition, I named my machine "Linuxbox" and created a user account named "me". You, of course, can use any name you like.
  • At the "Select and install software" screen you will be presented with a group of check boxes for different sets of packages to install. Using the space bar, select the "Print server" group and unselect the "Desktop environment" group.
  • If you have installed the system using the entire disk as suggested above, answer "yes" to the prompt on the "Install the GRUB boot loader on the hard disk" screen to install GRUB in the disk's master boot record (MBR).
The install should complete and prompt you to remove the install CD. Next, the machine will reboot and we should see the fruits of our labors.

A lot of boot messages should scroll by after the reboot and you will see at the very bottom a login prompt like this:

Debian GNU/Linux 5.0 linuxbox tty1

linuxbox login:

Enter the name root and then the root password and we will see a prompt like this:

linuxbox: ~#

Enter the command shutdown -h now and the machine will shutdown.

We're done for today.

Further Reading

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

Wednesday, February 25, 2009

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

When I see an old PC in the trash, I have a strong urge to rescue and adopt it like a stray puppy. My wife, of course, has very effective ways of constraining my behavior in this regard, so I don't have nearly as many computers as I want. I hate seeing computers go to waste. I figure if the processor and the power supply are still working, the computer should be doing something. So what if it can't run the latest version of Windows? It can still run Linux!

Over the next few weeks, I will show you how to take an old, slow computer and make it into a text-only Linux workstation with surprising capabilities, including document production, email, instant messaging, audio playback, USENET news, calendaring, and, yes, even web browsing.

Why would anyone want to build a text-only workstation? I don't know. Because we can! And besides, it's a great way to learn a bunch of command line stuff and that's why you're here, right?

So if you want to play along, find yourself a computer with a least the following:
  • Pentium processor or above
  • 64 MB or more of RAM
  • 2 GB or larger hard disk
  • PS/2 or USB mouse
  • A PCI Network card (no ISA or wireless please)
We're going to format over the existing software so don't use a valuable machine for this project. Many machines from the Windows 98 era should be good candidates. I will be using an HP Pavilion (circa 1996) with a 600 MHz Celeron, 320 MB of RAM and a 20 GB disk.

Good luck and I will 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, February 23, 2009

Bash 4.0 Released Today

Version 4.0 of everyone's favorite shell program was released today. I imagine this will be showing up in new Linux distributions soon. A copy of the release announcement is here.

Friday, February 20, 2009

The Unix (Linux) Frame Of Mind

If you are migrating from Windows to Linux, one of the barriers you will encounter (besides the myriad superficial differences in the user interface) is the whole "culture thing."

Using a Unix-like operating system involves more than learning where the buttons are located on the desktop. It requires a different way of thinking about your computer. On top of that, Linux requires that you learn about your relationship with the Free and open source software communities. That will be the subject, no doubt, of many future postings, but for now we'll talk about the Unix frame of mind.

To understand Unix, you have to understand its historical context. Unix certainly has its faults, but if you understand its history, you can see that many of its "features" are due to the state of computing during its formative years. But it's also important to realize that just because something is old does not mean that it is necessarily bad. Take for instance, the command line interface. If you listen to pundits and the PC magazine writers, you would think that the command line is the equivalent of waterboarding to the modern computer user. I liken use of a graphical user interface to watching television and the command line to reading a book. They are very different, but both are valid (and valuable) if used in the proper way.

So what is "the Unix frame of mind?" It is based on some the following principles:

The computer is multi-user. Unix was designed for "big" computers. Big, expensive computers that supported many users at the same time. This has a number of implications. For one, it meant a different security model. On a multi-user computer, it is essential that one user cannot trash another user, or the entire system. It also implies that communities can form among the computer's users. If you have Fedora or any of the other Red Hat family of Linux distributions, you may have noticed that it runs sendmail by default. This is part of the Unix tradition. Users on a system send email to each other. The first form of instant messaging was the write command which sent a text message to another user's terminal session.

Automate everything. Back in the 1960's IBM used a marketing slogan, "Machines should work. People should think." Yet today, we have millions of office workers sitting in front of PCs pumping their mice all day. Why? It's because the computer is not doing the work. The human is. The Unix way is to instruct the computer how to do the work and then forget about it. Back in the 1990s I marveled at the cron daemon. It could perform tasks on a scheduled basis. I remember leaving my PC on all night and letting it do the work I needed and having a summary of the results each morning. It did the work so I didn't have to.

Everyone programs. The computer is a tool, or rather, it is a huge collection of tools that can be arranged to perform work. To do this, you must program. You have to break your tasks into simple steps and arrange the tools to perform them. Unix actually makes this fairly simple. You can create pipelines of commands or write shell scripts. Have you noticed how, over the years, Windows has removed all the programming tools from its system? This keeps the users helpless. If they want a solution, they have to go out and buy it. By contrast, every major Linux distribution includes the shell, perl, python, text editors and thousands of tools for building solutions. If you need more, there is just about every programming tool under the sun available for immediate download.

A computer is not "easy to use." That is a marketing myth. A computer is no more easy to use than a violin, but with much study and practice, both can produce beautiful music.

It all depends on your frame of mind.

Every Linux user should learn something about the history of Unix. The Wikipedia is a good place to start:

http://en.wikipedia.org/wiki/Unix

Also check out Eric Raymond's The Art Of Unix Programming:

http://www.faqs.org/docs/artu/