_Introduction

This project is part of my ongoing studies with the FreeCodeCamp project. After learning about the basics of HTML and CSS and how it relates to Responsive Web Design, I am encouraged to test out my skills with real life projects. Here I´ve styled a beginner´s technical documentation page for Unix. All content here are excerpts from Tutorialspoint, a fantastic Unix resource.

Unix is a computer Operating System which is capable of handling activities from multiple users at the same time. The development of Unix started around 1969 at AT&T Bell Labs by Ken Thompson and Dennis Ritchie. This tutorial gives a very good understanding on Unix.

This tutorial has been prepared for the beginners to help them understand the basics to advanced concepts covering Unix commands, Unix shell scripting and various utilities. We assume you have adequate exposure to Operating Systems and their functionalities. A basic understanding on various computer concepts will also help you in understanding the various exercises given in this tutorial.

If you are willing to learn the Unix/Linux basic commands and Shell script but you do not have a setup for the same, then do not worry — The CodingGround is available on a highend dedicated server giving you real programming experience with the comfort of singleclick execution. Yes! It is absolutely free and online.

_What is Unix?

Back to top

The Unix operating system is a set of programs that act as a link between the computer and the user. The computer programs that allocate the system resources and coordinate all the details of the computer's internals is called the operating system or the kernel.

Users communicate with the kernel through a program known as the shell. The shell is a command line interpreter; it translates commands entered by the user and converts them into a language that is understood by the kernel.

  • Unix was originally developed in 1969 by a group of AT&T employees Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna at Bell Labs.
  • There are various Unix variants available in the market. Solaris Unix, AIX, HP Unix and BSD are a few examples. Linux is also a flavor of Unix which is freely available.
  • Several people can use a Unix computer at the same time; hence Unix is called a multiuser system.
  • A user can also run multiple programs at the same time; hence Unix is a multitasking environment.

_Unix architecture

Back to top

Here is a basic block diagram of a Unix system:

Diagram showing architecture of Unix

The main concept that unites all the versions of Unix is the following four basics:

  • Kernel − The kernel is the heart of the operating system. It interacts with the hardware and most of the tasks like memory management, task scheduling and file management.
  • Shell − The shell is the utility that processes your requests. When you type in a command at your terminal, the shell interprets the command and calls the program that you want. The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are the most famous shells which are available with most of the Unix variants.
  • Commands and Utilities − There are various commands and utilities which you can make use of in your day to day activities. cp, mv, cat and grep, etc. are few examples of commands and utilities. There are over 250 standard commands plus numerous others provided through 3rd party software. All the commands come along with various options.
  • Files and Directories − All the data of Unix is organized into files. All files are then organized into directories. These directories are further organized into a tree-like structure called the filesystem.

_System bootup

If you have a computer which has the Unix operating system installed in it, then you simply need to turn on the system to make it live.

As soon as you turn on the system, it starts booting up and finally it prompts you to log into the system, which is an activity to log into the system and use it for your day-to-day activities.

_Login Unix

When you first connect to a Unix system, you usually see a prompt such as the following:

login:

_To log in

  • Have your userid (user identification) and password ready. Contact your system administrator if you don't have these yet.
  • Type your userid at the login prompt, then press ENTER. Your userid is case-sensitive, so be sure you type it exactly as your system administrator has instructed.
  • Type your password at the password prompt, then press ENTER. Your password is also case-sensitive.
  • If you provide the correct userid and password, then you will be allowed to enter into the system. Read the information and messages that comes up on the screen, which is as follows.

    login : amrood
    amrood's password:
    Last login: Sun Jun 14 09:32:32 2009 from 62.61.164.73
    $
        

You will be provided with a command prompt (sometime called the $ prompt ) where you type all your commands. For example, to check calendar, you need to type the cal command as follows:


    $ cal
    June 2009
    Su Mo Tu We Th Fr Sa
        1  2  3  4  5  6
    7  8  9 10 11 12 13
    14 15 16 17 18 19 20
    21 22 23 24 25 26 27
    28 29 30
    $
        
Profile picture of programmer Dennis Ritchie

UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.

Dennis Ritchie

_Listing files

Back to top

To list the files and directories stored in the current directory, use the following command:

$ls

Here is the sample output of the above command:


    $ls

    bin       hosts   lib     res.03
    ch07      hw1     pub     test_results
    ch07.bak  hw2     res.01  users
    docs      hw3     res.02  work
        

The command ls supports the -l option which would help you to get more information about the listed files:


    $ls -l
    total 1962188

    drwxrwxr-x  2 amrood amrood      4096 Dec 25 09:59 uml
    -rw-rw-r--  1 amrood amrood      5341 Dec 25 08:38 uml.jpg
    drwxr-xr-x  2 amrood amrood      4096 Feb 15  2006 univ
    drwxr-xr-x  2 root   root        4096 Dec  9  2007 urlspedia
    -rw-r--r--  1 root   root      276480 Dec  9  2007 urlspedia.tar
    drwxr-xr-x  8 root   root        4096 Nov 25  2007 usr
    drwxr-xr-x  2    200    300      4096 Nov 25  2007 webthumb-1.01
    -rwxr-xr-x  1 root   root        3192 Nov 25  2007 webthumb.php
    -rw-rw-r--  1 amrood amrood     20480 Nov 25  2007 webthumb.tar
    -rw-rw-r--  1 amrood amrood      5654 Aug  9  2007 yourfile.mid
    -rw-rw-r--  1 amrood amrood    166255 Aug  9  2007 yourfile.swf
    drwxr-xr-x 11 amrood amrood      4096 May 29  2007 zlib-1.2.3
    $
        

Here is the information about all the listed columns:

  • First Column − Represents the file type and the permission given on the file. Below is the description of all type of files.
  • Second Column − Represents the number of memory blocks taken by the file or directory.
  • Third Column − Represents the owner of the file. This is the Unix user who created this file.
  • Fourth Column − Represents the group of the owner. Every Unix user will have an associated group.
  • Fifth Column − Represents the file size in bytes.
  • Sixth Column − Represents the date and the time when this file was created or modified for the last time.
  • Seventh Column − Represents the file or the directory name.

_Metacharacters

Back to top

Metacharacters have a special meaning in Unix. For example, * and ? are metacharacters. We use * to match 0 or more characters, a question mark (?) matches with a single character. For example:


    $ls ch*.doc
        

Displays all the files, the names of which start with ch and end with .doc


    ch01-1.doc   ch010.doc  ch02.doc    ch03-2.doc 
    ch04-1.doc   ch040.doc  ch05.doc    ch06-2.doc
    ch01-2.doc ch02-1.doc c
        

Here, * works as meta character which matches with any character. If you want to display all the files ending with just .doc, then you can use the following command:


    $ls *.doc
        

_Hidden files

Back to top

An invisible file is one, the first character of which is the dot or the period character (.). Unix programs (including the shell) use most of these files to store configuration information.

Some common examples of the hidden files include the files:

  • .profile − The Bourne shell ( sh) initialization script
  • .kshrc − The Korn shell ( ksh) initialization script
  • .cshrc − The C shell ( csh) initialization script
  • .rhosts − The remote shell configuration file

To list the invisible files, specify the -a option to ls:


    $ ls -a

    .         .profile       docs     lib     test_results
    ..        .rhosts        hosts    pub     users
    .emacs    bin            hw1      res.01  work
    .exrc     ch07           hw2      res.02
    .kshrc    ch07.bak       hw3      res.03
    $
        
  • Single dot (.) − This represents the current directory.
  • Double dot (..) − This represents the parent directory.
Profile picture of programmer Ellen Ullman

I came of technical age with UNIX, where I learned with power-greedy pleasure that you could kill a system right out from under yourself with a single command.

Ellen Ullman

_Creating files

Back to top

You can use the vi editor to create ordinary files on any Unix system. You simply need to give the following command:


    $ vi filename
            

The above command will open a file with the given filename. Now, press the key i to come into the edit mode. Once you are in the edit mode, you can start writing your content in the file as in the following program:


    This is unix file....I created it for the first time.....
    I'm going to save this content in this file.
            

Once you are done with the program, follow these steps:

  • Press the key esc to come out of the edit mode.
  • Press two keys Shift + ZZ together to come out of the file completely.

You will now have a file created with filename in the current directory.


    $ vi filename
    $
        

_Editing files

Back to top

You can edit an existing file using the vi editor. We will discuss in short how to open an existing file:


    $ vi filename
        

Once the file is opened, you can come in the edit mode by pressing the key i and then you can proceed by editing the file. If you want to move here and there inside a file, then first you need to come out of the edit mode by pressing the key Esc. After this, you can use the following keys to move inside a file:

  • l key to move to the right side.
  • h key to move to the left side.
  • k key to move upside in the file.
  • j key to move downside in the file.

So using the above keys, you can position your cursor wherever you want to edit. Once you are positioned, then you can use the i key to come in the edit mode. Once you are done with the editing in your file, press Esc and finally two keys Shift + ZZ together to come out of the file completely.

_Display content of a file

Back to top

You can use the cat command to see the content of a file. Following is a simple example to see the content of the above created file:


    $ cat filename
    This is unix file....I created it for the first time.....
    I'm going to save this content in this file.
    $
            

You can display the line numbers by using the -b option along with the cat command as follows:


    $ cat -b filename
    1   This is unix file....I created it for the first time.....
    2   I'm going to save this content in this file.
    $
        
Profile picture of cartoonist Scott Adams

If you have any trouble sounding condescending, find a Unix user to show you how it's done.

Scott Adams

_Counting words in a file

Back to top

You can use the wc command to get a count of the total number of lines, words, and characters contained in a file. Following is a simple example to see the information about the file created above:


    $ wc filename
    2  19 103 filename
    $
            

Here is the detail of all the four columns:

  • First Column − Represents the total number of lines in the file.
  • Second Column − Represents the total number of words in the file.
  • Third Column − Represents the total number of bytes in the file. This is the actual size of the file.
  • Fourth Column − Represents the file name.

You can give multiple files and get information about those files at a time. Following is simple syntax:


    $ wc filename1 filename2 filename3