UNIX Tutorial

  • UNIX is one of computer operating system, high-function, interactive, multi-tasking, multi-user operating system.
  • UNIX originated at AT&T Bell Laboratories in the late 1960s. It is based on an open-architecture in which all interfaces and inter-process communication is standard. This simplifies expansion of the operating system and development of new system and application features.
  • This tutorial is mainly prepared for the beginners to understand the basic concepts of Unix, Unix commands, Unix Shell Scripting.

History of Unix:

  • The first version of Unix came from AT&T in the early 1970s (Unix is old!).
  • Unix was developed by programmers and for programmers.
  • Unix is designed so that users can extend the functionality
    • To build new tools easily and efficiently
    • To customize the shell and user interface.
    • To string together, a series of Unix commands to create new functionality.
    • To create custom commands that do exactly what we want.

Unix is one of the operating system which is made up of three parts.

  • Kernel
  • Shell
  • Programs

Kernel:

The kernel is the core of the Unix operating system. It allocates the time and memory to the programs and handles the communications is response to the system calls.

Shell:

The Shell acts an interface between Kernel and User. The Shell is a command line interpreter (CLI). It interprets the user commands and arranges them to be carried out. In other words, Command Interpreter that turns text that you type (at the command line) in to actions.

Programs:

The commands are themselves called as programs in Unix. The UNIX shell program interprets user commands, which are either directly entered by the user, or which can be read from a file called the shell script or shell program. Shell scripts are interpreted, not compiled.

What is Shell?

  • The Shell acts as an interface to the Unix system. It gathers input from user and execute the programs based on the input. When the program execution is complete, it displays the program’s output.
  • Shell is an environment in which we can run our commands, programs and shell scripts.

Below are the different Popular Shell Types:

Bourne Shell  – The default command prompt of a Bourne type shell is character $

Bourne shell has the following subcategories

Sh              à Bourne Shell

Ksh            à Korn Shell

Bash          à Bourne-Again Shell

C Shell – The default command prompt of a C Shell is character %

File Management:

All the data in Unix is organized into files. All the files are organized into Directories. The people working in Unix will spend most of the time in working with files.

Following are the types of file management system in Unix.

Ordinary files:

This is a normal text file on the system that can contains any details on it.

Directories:

The directories in the Unix File management is the storage of files. In other words, it can be called as folders in windows.

How to list the files and directories in Unix?

$ls

Ex:

In the above output, file.txt, test.1, test.2 and bin are files and directories.

Basic useful Unix commands:

ls: –

To lists the files and directories from the Unix directory.

Ex:

Options in ls command in Unix:

ls -l : –

Long listing of files. List in long format, giving mode, number of links, owner, group, size in bytes and time of last modification for each file.

Ex:

ls -r: –

To reverse the order of sort to get reverse (descending) collation or oldest first, as appropriate.

Ex:

ls -t: –

To sort by time modified (latest first) before sorting alphabetically.

Ex:

In the real world, most of the time we will be using the command “ls -lrt” to list the files in the orders.

Ex:

  • By looking at the above examples, you can easily identify the difference between each of the commands.
  • There are many number of options available in Unix for ls command. You can get to know each option using man command.
  •  Man command in Unix:

$man ls

man command is a help command in Unix. The main use of this command is to find manual information by keywords.

man accesses information from the HP-UX manual pages.  This command is useful to,

  • List all manual entries whose one-line description contains any of a specified set of keywords.
  • Display or print one-line descriptions of entries specified by name.
  • Search on-line manual directories by entry name and display or print the specified entry or entries.
  • Search a specified on-line manual section (directory) and display or print the specified entry or entries in that section

More command:

If the file size is very huge and when we use view command to open the file, it will take more time to load / open the file. During that time, we can use more command to look at the content of the file. The more command shows the first part of a file, just as much as will fit on one screen. Just hit the space bar to see more or q to quit.

Command to use :  $more filename

Ex: more bigfile.txt

hp2033:csmssupp:/home/csmssupp/sss=> more bigfile.txt

Vi / View command:

  • In Unix to view the file, we can use vi or view command. If you use view command then it will be read only. That means you can view the file but you will not be able to edit anything in that file. If you use vi command to open the file then you will be able to view/update the file.
  • In addition to this, by using the “vi” command the new files in the Unix system will be created.
  •         In the below example, we are creating the new file called “newfile.txt” using the command “vi”.

  Ex: vi newfile.txt

Touch command:

This command is used to create the empty files in Unix system. The size of the file created using touch command will be 0 bytes. We will be able to add the contents into the file using vi command.

Ex: touch TestFile.txt

Mv command:

  • In Unix, we have an ability to move the files to different name or can move the file to different directory.
  • The below command is used to move the file to different name within the directory.

Ex: mv test.1 test.txt

hp2033:csmssupp:/home/csmssupp/sss=>mv test.txt test1.txt

Note: when we use mv command the timestamp of the file will not be changed.

The below command is used to move the file to different directory.

Ex: mv test1.txt /home/csmssupp/eee

cp command:

copies a file into same directory with different names or copies a file into different directory with same or different names.

Ex: cp test.txt test1.txt

Copy from one directory to another

Ex:

Note: When we use copy command, the timestamp of the file will be changed

Rm command:

This command is used to remove the file.

Ex: rm abcde

Cat command:

This command one of the most frequently used commands in Unix. This command is used to read the content of the files in the command prompt. Using “cat” command we will be able to only read the file. We cannot modify or update anything on the file.

Ex: cat file.txt

Diff command:

  • This command is mostly used to compare the 2 files and shows the difference between the 2 files.
  • First let’s see the content of the 2 files, so that it will be easy to understand how the diff command displays the results.

Below are the content of the 2 files,

The first 2 lines of the 2 files are same and the second file has the extra 2 different contents. Hence the diff command shows the details on the difference as below. It also shows the line number which has difference. Based on our example, the lines 3 and 4 are having the difference.

Ex: diff file.txt test.txt

Wc command:

This command is used to find the number of lines, words and characters in the file.

Ex: wc filename

In the above example file, it has 85 lines, 435 words and 4499 characters on it.










Share this website !!!
Facebook Twitter Linkedin