Linux is the most widely used variant of Unix. Linux is a very powerful operating system which has been around for more than 30 years. Initially, it was primarily been used by industry and academia. However, since Linux, anyone can have a Unix system installed on their computer. Having Linux on your computer is like having an industry strength product. Much of the Internet still runs on Linux.

Since Linux has been in the academia for decades, much of its software is available for free. In addition, there is no shortage of blogs full of helpful comments.

Unix is not a monolithic entity like Microsoft Windows. There are many types of Unix. The most widely used and freely available version of Unix is Linux. Linux itself has several versions. Unix comes in many different flavors but it is essentially the same operating system and most of the commands are the same.

Main components of a computer

The physical components of a computer are referred to as the hardware and the code is referred to as the software. Computer hardware is made up of a number of different components, such as CPU (central processing unit), memory, and disks. An operating system enables all the different hardware components in a computer to interact with each other. There are many different operating systems such as UNIX, Linux, Microsoft Windows, etc. An operating system is a collection of programs and files which manage and instruct computer hardware.

Hardware

The four main components of a computer are:

  • CPU
  • Runtime memory
  • long-term memory
  • i/o devices

CPU – central processing unit CPU is the processor which executes instructions. CPUs are traditionally measured in clock cycles e.g. 6.0 GHz.

Run-time memory Random access memory – RAM is an example of run-time memory. It is live when the computer is on. It loses its content as soon as we cut power. Since it is very fast, program stored in the long-term memory execute in run-time memory. Program and data being used by the computer are copied onto the RAM. This data remains the RAM as long as the program is running. When a program is done, it is removed from the RAM and this space is allocated to another program.

Long-term memory Hard drives are the primary long term memory of the computer. All installed programs are stored on the hard drive. All your data is also stored on your hard drive.

I/O devices Computers can read from input devices such as keyboard and mouse while output to devices such as the monitor and the printer.

Measuring Memory Memory is measured in bytes. A byte is the number of slots used by a computer to represent one character.

1kbkilobyte1024 bytes (for simplicity, 1000kb)
1mbmegabyte1000 kilobytes
1gbgigabyte1000 megabytes
1tbterabyte1000 gigabytes or approximately one trillion bytes

External memory In addition to RAM and hard drive, there is a whole array of memory devices available, each with its own strong and weak points.

CDs and DVDs CDs are DVDs are gradually losing their importance to Flash memory and high speed Internet. Most new computers do not come equipped with CD/DVD readers.

Flash Memory We all have heard about USB. It is a revolution over older sockets. If you look at the back of your computer, you will find sockets of all shapes and sizes. Each of them with the exception of the serial port, is dedicated to a specific type of device. For example, you cannot attach a printer on a ps2 keyboard socket. USB technology has removed this restriction. It is a standard socket which accepts digital rather than an analog signal and you can plug in any device which support USB technology.

Flash memory (used in USB memory sticks) is a fast memory which can be connected to almost any computer and usually works painlessly. It is very compact and very easy to carry around. It is the technology which made floppy disks and CD/DVDs obsolete.

External hard drives USB technology is very fast. This speed has finally made external hard drives possible. A typical external hard drive can now hold hundreds of megabytes of data, just like a normal hard drive. Mini HD is a technology which aims to miniaturize this technology. This new technology is expected to bring tough competition to the flash disks.

Tape drives Tape drives have existed since the 1970s. The progress in this field has been steady and remarkable, yet it has gone unnoticed by the general public. A small collection of tape drives can backup terabytes of data. This technology almost obsolete.

Internet Internet can be used for data storage. In fact, many people use it for data storage. Services like xdrive.com and dropbox have existed for years. They allow you to upload your data where it is guaranteed not to be lost since there is a team of experts watching out for viruses, doing backups, etc. In addition, you can access your data wherever you find access to the Internet. No need to worry about losing tiny flash memory sticks. With massive server space for gmail account, Google is slowly moving into the domain of data storage online.

Software

The code on your computer is the software.

Operating System

An operating system is the software responsible for the direct control and management of

  • hardware
  • basic system operations
  • running application software
  • files and directories

The operating system interprets instructions from the user or an application and instructs the computer’s hardware. It handles the input, output, and keeps track of the data. It also enables different devices such as keyboard and CPU to communicate with each other. Examples of operating systems are UNIX, Linux, Microsoft Windows 10, and Mac OS.

Application Software Application software is any software that runs on top of the operating system. Microsoft Word, Adobe PhotoShop, and Oracle are some examples. Whenever you install a software on your computer which already has an operating system installed, you are installing an application software.

UNIX operating system

The UNIX system contains 3 main components:

  • Kernel
  • Shell
  • Directory structure

Kernel The kernel is the master program which manages all the resources of the computer, including:

  • File systems
  • Device management
  • Process management
  • Memory management

Shell The shell is an interface between the user and the kernel. It is primarily a command interpreter. It accepts commands, interprets them, and then executes them. There are many different shells but Bash is the most widely used.

Common Shells

bashBourne again shell
shshell
cshC shell
tcshTenex C shell (not tab-completion-extended C shell)
tclshTcl shell
kshkorn shell
asha shell
bshbourne shell (/bin/sh)
zshthe Z shell
zshthe jail shell

Directory structure See next lesson

Linux command line syntax

Linux command lines can be as simple, one-word entries like

pwd

or complex sentences like:

ls -R lists 

Linux commands may or may not contain arguments. An argument is an option or a filename. A Linux command is written as:

command option(s) filename(s)

Options modify the way a command functions. For example, ls would simply print the directory listing. ls -al would give a listing with file details.

Linux has a lot of commands. Linux command line software such as vi editors also comes with its own set of commands. Attempting to memorize all the commands and their various options would be a waste of time. Instead, you should learn the commands and their options as you use them.

Every now and then, you would come across a frozen terminal. In such cases, try hitting the return key, ctrl-Q, ctrl-D or ctrl-Z.

Linux Directory Structure

An operating system is capable of storing data in an orderly fashion. A directory tree is used to organize and data. A organizes files hierarchically, with a root that branches into subdirectories. Thus the tree structure allows users to easily organize and find their data. Just like your paperwork, the better you classification, the easier it would be to find the documents when you need them. Each file and directory in an operating system has unique address thanks to the tree structure.

Path

A path uniquely identifies a particular file or directory by specifying its exact location in the directory. The symbol slash ” / ” separates names of files. In a Linux operating system, everything including directories is considered files.

There are two types of paths. The Linux directory structure starts from the root “/”. The absolute path specifies a file or a directory in relation to the entire Linux system. The relative path describes the location of a directory or a file as it relates to the current directory.

Each directory contains two links, “./” and “../”, which refer to the current directory and its parent directory. Relative addresses use “../” to backtrack and forward addresses to move forward.

Suppose your current directory is

/home/usr/student

You wish to go to the images directory,

Using absolute path:    /home/usr/student/documents/images
Using relative path:    documents/images

To backtrack to /home/usr, type cd ../

Naming files and directories

Files can be created using alphanumeric characters, underscores, periods, and hyphens. It is wise to avoid all other characters even if the operating system would allow you to use them.

When naming a files or folders, it is very important to give meaning full names. This would greatly help you in find a file when it is needed. Suppose there are two users, Alice and Bob, both of whom using completely different naming schemes.

Alice’s files:

$ ls ~
work    home    photos
$ cd work
Accounts.dat    faq.txt    todo.list

Bob’s files:

$ ls ~
Dir1    dir2    dr3
$ cd Dir1
1.txt    2.txt    3.txt

Right now we are only looking three files and 3 directories. It is already clear who would be capable of finding the “to do list” with much less ease and frustration. Bob has no choice but to open and read all his files until he reaches his to do list. Now imagine that Bob has to sift through hundreds of files. Most computer users have somewhere between hundreds to thousands of files.

It is wise to aim for uniformity rather than uniqueness in file naming since humans are better at remembering and following patterns. Following are some rule of thumbs:

Classify files by their function. Don’t put your vacation photos in the accounting directory. All files of the same type must have the same extension The filename should be indicative of the content of the file. The filename should be sufficient to remind you of what your file contains. Try to keep the name as short as possible but not shorter. If this is not possible, add a readme.txt file next to the file.

Linux is very powerful and allows to much more control over you own computer. More control means fewer forced restrictions. This in turn resulted in a number of conventions. For example, Microsoft Windows requires file extension to define the file type. Linux has no such restriction but conventions define that you should use the extension to indicate the file type. It is often wise to following established conventions. Habits, both good and bad, are difficult to break. So why not start with good habits. Get in the habit of following well-established conventions.

Directory commands

Following is a list of command which would help you navigate the UNIX directory structure. UNIX also offers graphical environments to navigate the directory structure but very often you would have to come back to the command line. Therefore, it is a good idea to learn and use these simple commands.

Summary

cd:    change directory
pwd:    identifies the absolute path to the current directory
ls:    displays the contents of the directory
ls -a:    display all files including hidden files
ls -F:    display file types. 
Directory    /
Executable    *
ASCII        none
Symbolic link    @
ls -l    list files with their details
ls -R    recursive listing of subfolders and their files
ls -t    display sorted by time
ls -r    display in reverse order

Shell Metacharacters Shell metacharacters are specific characters which have a particular meaning to the shell.

cd ~    go to the home directory, not supported by bourne shell
cd -    same as pwd. Korn, switch between two directories
ls m*    display all files beginning with f such as my, man, mime, etc.
ls m?    display all files beginning with an m followed by one character such as my.
ls [a-c]*    display all files beginning with an a, b, or c. 

The asterisk is a wildcard meaning on or more characters. The question mark matches any single character. The square brackets [ ] match a set or range of characters for a single character position.

Listing files and directories

When you first login, your current working directory is your home directory. Your home directory has the same name as your user-name, for example, ee91ab, and it is where your personal files and subdirectories are saved.

To find out what is in your home directory, type

% ls

The ls command lists the contents of your current working directory.

There may be no files visible in your home directory, in which case, the UNIX prompt will be returned. Alternatively, there may already be some files inserted by the System Administrator when your account was created.

ls does not, in fact, cause all the files in your home directory to be listed, but only those ones whose name does not begin with a dot (.) Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information. They are hidden because you should not change them unless you are very familiar with UNIX!!!

To list all files in your home directory including those whose names begin with a dot, type

% ls -a

As you can see, ls -a lists files that are normally hidden.

ls is an example of a command which can take options: -a is an example of an option. The options change the behaviour of the command. There are online manual pages that tell you which options a particular command can take, and how each option modifies the behaviour of the command. (See later in this tutorial)

History Command

Linux systems store the commands you type. To get a chronological list of commands you typed, use the following command:

$ history

To repeat a previous command you can type:

$ !!

To repeat a previous command

$ !n    (where n is a number from your history list)

or

$ !string    (where string is a series of characters) 

This would repeat the most recent command in your history whose first characters match string To delete a history record:

$ history -d line_number

To clear all the history:

$ history -c