Linux Shells

Boot, login, and start Secure Telnet/Secure Shell or PuTTY.

Log in with your UNM user name and password.

Check Your Shell

Command:

echo $SHELL

Your answer may be:

/bin/sh # the Bourne shell
/bin/csh # the C shell
/bin/bash # the Bourne Again shell
/bin/ksh # the Korn shell

Definitions

Commands: the instructions you give to the system

Files: globs of data that have been given filenames. These could contain graphics, music, text or programs.

Directories: in Windows we call these Folders. Think of something like a file cabinet drawer that can contain many files. Directories can contain other directories.

Directories are files. A directory file is a list of other files.

Environment: the collection of items that describe your unique computing session. These describe what programs you use, which printers, where you documents are stored by default, the email program you prefer to use, and a LOT more.

Process: a command or application running on the computer. You might want to call this a “program,” but actually an application may contain several programs, each of which may spawn many processes. Processes run in the “user space.”

Thread: an application running in “kernel space.”

Job: this is closer to what you’d think of as a “program.” It’s the sequence of instructions that’s given to the computer to perform a task. When the task is done, the job concludes.

Logging In To A Shell

When you sit down at a Linux workstation or make a connection to a Unix server, you start out at a login prompt. If you only see a flashing cursor, press the Enter key and you’ll be given the prompt:

login:

Your Username

To get any further, you have to have a user name (“username”). If you are registered with UNM, you have one; usually it’s the same as your email address. (This becomes an important issue we’ll explore later.)

Unix is case-sensitive, meaning that “A” is different than “a.” You have to enter your username correctly or this won’t work. Press the Enter key when you’re done:

Your Password

Now you’ll get a password prompt:

password:

Enter the password we supply to you.

Checking Your User Information

Now that you’ve finally logged in and taken care of any password change, you’re operating in your shell. One of the first things you can check is your own user information:

id

whoami

who

w

finger username

groups

These will show your userid number and name, your main group affiliation, and a list of all the groups of which you are a member, among other things.

There Are Lots Of Shells

Another term for a shell is “command interpreter.” Remember Dennis Richie, inventor of the C programming language? The first thing he needed, once he got his PDP7 “Unics” computer working, was a command interpreter to actually run commands. Thus was born the “C Shell,” csh, one of hundreds of program-name jokes in the Unix world.

Other Shells

Other shells include:

  • the Korn shell (ksh or the Posix shell),
  • the Bourne shell (sh),
  • the Perl shell (perl),
  • csh/tcsh (C shells),
  • The Bourne Again SHell (bash),
  • rsh (remote shell),
  • ssh (secure shell)
  • and more.

Some shells can connect to remote computers.

Some shells encrypt their traffic for security.

Some pass traffic as plain text, like Telnet.

The closely-related Bourne, bash and Korn shells offer lots of nice features like completion, which means if you type the beginning of a file name, for instance, bash will try to complete it for you.

The Bourne Shell

Other programmers needed different features in their shells, so they wrote their own command interpreters. Evolution occurred, survival of the fittest kicked in, and eventually the Bourne shell became the standard.

When this shell made the transition to the Linux world, if became the Bourne Again Shell, or bash. This is the default shell in most Linux distributions, but you can still choose to use a different shell.

On a Unix server, the default login shell will often be the C shell, /bin/csh. This is, unfortunately, a very “old school” choice, but one that’s easy to fix in the short term. Simply command:

bash # on a Linux box
 or
sh # on an AIX box
or
ksh # on an HP-UX box

For now, just be aware that we are studying bash under Linux and Bourne or Korn under Unix, and that this choice of shell is one of your environment variables.

This Is Your Command Line

When you are any user but root, Bourne/bash/Korn will give you this prompt:

$

with a flashing cursor where your text will be entered. If you use csh (or tcsh) your prompt will be:

>

Even more important is the visual cue the shell will give you to let you know you’re logged in as root:

#

Entering Commands

You’re ready to enter commands. You should know that:

  • Unix commands are case-sensitive.
  • Most are lower-case.
  • These commands are only going to work at a shell prompt.
  • You have to press the Enter key to make the command run.

Command Options

Commands often have options after the main command, and these options usually begin with a dash, for instance:

ls -l

You can add more than one option at a time:

ls –la

These “single-dash” options are formally called “System V” options. You will also see “no-dash” options (“BSD” options) with some commands, such as:

ps aux

Then there are the so-called POSIX options that are supposed to be common (at least to some degree of compliance) to any POSIX-compliant shell. They’re distinguished by double-dashes:

ls --reverse

Navigation Review

To move up one directory: cd ..

To move up two directories: cd ../..

To go back to your home, from anywhere: cd or cd ~

Note that the tilde ( ~ ) means “home,” and is relative for every user.

Of course, you can always specify your destination: cd /home/studenth/

Or go back to the immediately previous directory:

cd –

The man Command

You can always get information about a command by calling for a “manual page:”

man ls

will get you a detailed page of information on using the ls command.

The more Command

more = Show the contents of a text file one screen at a time.

Typing

more file.txt

will allow you to view, one page at a time, the contents of the file file.txt.

When viewing the text file, hitting <enter> advances the screen one line, while hitting <spacebar> advances the screen a page.

For help, type the letter h at the prompt while you’re in more.

When you’ve seen the whole file more will dump you to a command prompt.

The less Command

more may be nice for paging down through text files, but just try paging back up!

less, ironically enough, gives you “more.”

Use the same syntax as more:

less file.txt

Use the arrow keys or page up/page down to traverse the file in either direction.
When you want to leave less, type

q

(for “quit”).

The cat Command

There’s another way to view the contents of a text file (yes, really), and this one comes with a bonus.
The command:

cat file.txt

will display a file’s text and dump you to a command prompt.

One very useful option to cat is -n, for line numbering. Try this:

cat -n /etc/passwd

And, oddly, there is a tac command to read files in reverse order. This is especially handy for log files:

tac /var/log/messages

Con(cat)enate

But here’s the bonus: you can concatenate two or more text files with this command:

cat filename1 filename2 filename3

and you’ll see the contents of all three files, chained together (concatenated).
Remember this: this can be very handy later.