LUX 205 - Introduction to Linux/UNIX

Chapter 1, The Essence of UNIX and Linux

Objectives:

This lesson introduces the student to concepts that are important to understanding what UNIX and Linux are. Objectives important to this lesson:

  1. Operating systems
  2. UNIX and Linux
  3. UNIX and Linux shells
  4. User names and passwords
  5. Telnet and secure shell sessions
  6. Using command line instructions
  7. System administrators and changing the default password
  8. File manipulation
  9. Redirection
Concepts:

OS in contextThis chapter begins with a quick overview of operating systems. You may remember some of the ideas from NET 101. Any operating system should include some key features:

  • it coordinates the activities of programs and system hardware, allowing the programs to interact with hardware and each other
  • it performs startup and shutdown functions for the device that runs it
  • it typically includes one or more user interfaces
  • it is meant to run at startup, from a hard disk, a solid state drive, a bootable flash drive, or installed firmware

Several common operating systems are mentioned, and the text hints that different versions of operating systems are used by devices that have different purposes, such as Windows 7 or Windows 10, which are used for a personal computer, and Windows Server, which is used for a network server or a web server.

The text also discusses operating systems with regard to running devices on networks. Most networks operate with clients (devices that make requests) and servers (devices that answer or fulfill requests). The operating system that runs on a client in this kind of network may be different from an otherwise similar operating system that runs on a server, as noted in the Windows example above.Servers are allowed to request services from other devices (other servers), but their main purpose is to provide services.

Another kind of network is a peer-to-peer network, in which each device may request services from other devices, and may also provide services to other devices. The operating system on each device is more likely to be the same operating system in this kind of network.

On page 5, we are introduced to UNIX. The initial comments in this section, like those in most of the text, apply to both UNIX and Linux. The text informs us that a UNIX operating system can be installed on servers, on clients, on devices that are both clients and servers in a peer-to-peer network, and on standalone workstations. UNIX was invented before Linux, so the historical material starts there.

Bell Telephone logoTo understand the creation of UNIX, you need to know a little about Bell Labs. Once upon a time, before the US Government required that it be split up into several pieces (in 1984), the Bell System was a huge telephone/telecommunications company, that included a research and development division called Bell Telephone Laboratories, also known as Bell Labs. They invented a lot of things, including the UNIX operating system. At the time it was created, Bell Labs was not allowed to sell UNIX, so it was given away, mainly to universities who modified it as part of their own research and development programs.

As the text explains, this situation eventually led to two major versions of UNIX. One was controlled by Bell Labs itself, and it was called UNIX System V. Ownership of System V has changed over the years. The second version of UNIX is sometimes called BSD, which stands for Berkeley Software Distribution, because that version was standardized by the University of California, Berkeley.

Each of the two major versions of UNIX has its own history, features, and limits placed on its use. Linux was created as an operating system based on UNIX, but to be made freely available to anyone. It was primarily created at the University of Helsinki by Linus Torvalds, who wanted to call it Freax. It was called Linux by a co-worker who thought that was a better name.

UNIX and Linux, like most operating systems, are based on a pyramid model shown on page 7.

  • The bottom layer in the pyramid is the core of the operating system, called the kernel. The kernel communcates directly with the hardware of the system, such as the CPU, memory, and other essential computer components.
  • Some manuals describe a service layer next. This layer is not shown in your text. It contains modules that run in the background, and appear to be part of the kernel from the perspective of a user.
  • The middle layer shown in your text is the shell layer. UNIX and Linux can use several different shells, which are user interfaces. The typical user must interact with the kernel through a shell. A system administrator may be able to interact with the kernal directly, but this is never an option for average users.
  • The top layer of the pyramid is the user layer. On this layer, users sign in to the system, pass authentication, and are granted permissions to resources before they can run a shell.

As noted above, Linux was created as a free operating system, but it has been modified and adapted by several different entities, some of whom are listed on page 7. Some versions of Linux are still free, and others are for sale by their owners.

shell screen examplesOn page 8, the text discusses shells. Once a user has logged in to a UNIX system, a default shell is started. You can think of a basic shell as a command line interface to the kernel. The system you use may have several shells available, and you can start a new one at any time by typing its name as a command. The text mentions that you can set a personal choice for a default shell in a configuration file.

  • Bourne shell, the default shell on most UNIX systems, is started by entering the command sh.
  • Korn shell, created by David Korn, is based on the Bourne shell. It is started by entering the command ksh.
  • C shell, often found in BSD versions of UNIX, uses a grammar based on the C language. It may be started by entering the command csh, or tcsh, if the system is using the TENEX version of the C shell.
  • "Bash shell" is redundant, because Bash stands for Bourne Again Shell. It uses features from the Bourne shell and the Korn shell. It is started with the command bash. Bash is the default shell on many Linux versions.
  • The text also mentions the A shell (ash) and the z shell (zsh) which are both adaptations of other shells.

Once you learn to use the commands available in a given shell, you may want to store command sequences in shell script files which you can then execute as programs.

As mentioned above, you need to authenticate to a UNIX system to be granted the rights assigned to your ID. This means that you need a valid user ID and a valid password for that ID. On page 10, the text mentions that there are different rules that may be set for the complexity and length of user IDs and passwords. Make sure you know the rules before choosing either. That same part of the text lists five ways you might connect to a UNIX or Linux system:

  • Using a Telnet or SSH connection from a remote computer. This typically requires that your current workstation is either on the same network as the UNIX/Linux device you are connecting to, or that you are connected to a telecommunication network (such as the Internet) that can connect to the network that contains that UNIX/Linux host. SSH is more commonly used since the removal of Telnet from the list of programs included with Windows. This is actually better, since Telnet did not include authentication in most of its forms, and Secure Shell includes authentication by design.
  • Using client software on your workstation to connect to the UNIX/Linux host when you are both on the same client/server network.
  • Using a peer-to-peer connection in a peer-to-peer network.
  • Using a login prompt on a stand-alone computer that is running UNIX or Linux.
  • Using a dumb terminal on a network to connect to a UNIX/Linux host on a mainframe or other type of computer that is running UNIX or Linux.

In our classroom, we plan to use a variation on the fourth method, which is to install Linux on a virtual machine that will be run on each workstation in the lab. The text discusses logging in with a command line interface and with a GUI, which may be implemented through several different methods, such as X Windows or GNOME. These will be discussed in a later chapter.

Using a command line interface is the simplest and most common way to use a UNIX/Linux system. Let's take it from the point of logging in. Before typing anything on a UNIX system, a user should be made aware that UNIX cares more about the case of letters than any other operating system. All commands should be typed exactly as noted, including the use of capitalization. YOU HAVE BEEN WARNED!

When the system is started, the first thing the user should notice is the system asking for the user ID. It does so by presenting the login prompt which may look like this:

login:

The user enters the ID that the system administrator assigned, and presses enter. The system will next ask for the user's password by presenting the password prompt:

password:

The user should enter the current password assigned by the system administrator, or set by the user. A new user should be warned that what is typed at a password prompt is not echoed on the screen. This is normal, and is done as a security measure.

A user may change a password by entering the passwd command. Since this could also be done by someone other than the user, if the user walks away from the workstation for a few minutes, the first thing the passwd program asks for is the current password, with the prompt

Old password:

This is for the user's security. A user should keep a password private, and not tell it to anyone who might lock them out of the system for a joke or for spite. After entering the Old password, the user is asked for a New password, twice. This is to make sure the user knows what was typed and can repeat it.

When a user finishes a UNIX session, it is proper to log off the system. This can be done a number of ways. At a UNIX prompt, the user may type the command exit which should end the current shell session. Also, the user may press CTRL-d, that is the lower case d while the control key is held down. This will also end the current shell session. If you have started a new shell inside your current shell, the exit command should only terminate the new one, not the outer one. Note: the two commands above are valid for the Bourne, Korn, and Bash shells, but not for the C shell. For that shell, use the logout command. Other variations are listed on page 23.

As noted in the text, the UNIX system has hundreds of commands available to the user. This is confusing to the user who wants to learn them all. Most users do not need to use them all. This course will demonstrate some useful ones.

The date command reports the current date, time, time zone and year to the user. It is issued to the system simply by entering the word date on the command line. This is useful for users who work so long on the system that they forget who and where they are.

If the user has truly forgotten who he/she is, the who command may be helpful. It reports the user IDs of all users on the system at the time the command is given. It also has options which demonstrate the most common way to modify UNIX commands. Most commands follow this syntax:

command [-options] [objects]

The options usually (but not always) follow a hyphen, and they tell the command program HOW to carry out the command. The objects are usually the files (remember: UNIX thinks everything is a file) that the command is to be carried out upon. If you are to use a hyphen, do not put a space between the hyphen and any option letters. The text refers to the list of objects as the list of arguments, which is also correct. Arguments are what you pass to a function in math and in programming.

If the user types

who am i

the system will respond with the user's ID, terminal number and the date of login. This method uses no hyphen. If the user types

who

the system will respond with the same information about all users currently on the system. The command may be issued as

who -H

which will print column headers on the screen. Another way of using the command is just

who -q

which reports a count of current users.

Another command that uses options is the cal command. It activates UNIX's built in calendar program and shows a calendar page for the month and year a user requests. This command, however, does not use hyphens. Enter the command

cal 12 1997

and the system will show you a calendar page for December of 1997. You must use the full four digits for the year, such as 1997. If you enter

cal 12 97

UNIX will assume you want to look at the month of December in the year 97 (no leading digits). Try this command:

cal 9 1752

Hint: In that year, some people's calendars changed. Why and for whom? The text explains that the cal command can also tell you the Julian date for a particular day or sequence of days.

On many UNIX systems there are tutorial programs that can be started with the learn command. Working your way through this utility may be useful to you.

The help command is more common than learn. It takes you through help about certain common UNIX commands. It is not, however, universally liked, and may be of less use to you than the man command. This command activates the on-line manual for UNIX. It may be issued by itself on a command line, or you may type the word man followed by a specific command you would like to see the manual pages for.

Sometimes, the man command gives you more information than you actually need at the moment. The whatis command is used to display shorter descriptions of other commands. Note the procedure on the bottom of page 21 that is used to create the database that whatis reads. This database must be created by someone with administrator rights before the whatis command will work properly on some versions of UNIX/Linux.

On page 24, the text discusses the role of the administrator of a UNIX/Linux system. This role may be called system administrator, superuser, or root. Note the differences in the command lines for the root user and ordinary users shown on that page.

On page 22, the text discusses a reason to prefer some shells over other shells. It describes the fact that the Bash shell suports use of the left and right arrow keys to move your cursor when you are trying to edit a command line. The discussion continues for a couple of pages.

On page 25, the text mentions that several commands can be used to read the contents of files stored on a UNIX/Linux system. The cat command means to concatenate, and with only a filename as an argument, it means to concatenate the file to the screen. The command is:

cat filename

This is fine to put a short file on the screen. Our author mentions that a long one will scroll up the screen too fast to read. In that case, I recommend using the command with two changes:

cat filename | more 

This command uses the pipe character (probably the shift of the backslash on your keyboard) to send output of the cat command through the more command, causing the display to pause when the screen is full. You will see a prompt about pressing a key to seen the next screen full of text. Much easier to read.

Related to this use of the cat command is the last discussion on page 26, which concerns redirection. Redirection is simply sending or pulling data in a way that is not the default way. For example, we see in the example above that the pipe operator can be used to capture the output of one function, and then send that output as the input to another function. This method does not save the output of the first function. In the projects for this chapter, you will use a method that does.