What Is UNIX

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

What is UNIX?

UNIX is an operating system which was first developed in the


1960s, and has been under constant development ever since. By operating system, we
mean the suite of programs which make the computer work. It is a stable, multi-user, multi-
tasking system for servers, desktops and laptops.

UNIX systems also have a graphical user interface (GUI) similar to Microsoft Windows which
provides an easy to use environment. However, knowledge of UNIX is required for
operations which aren't covered by a graphical program, or for when there is no windows
interface available, for example, in a telnet session.

Types of UNIX

There are many different versions of UNIX, although they share common
similarities. The most popular varieties of UNIX are Sun Solaris, GNU/Linux, and MacOS X.
Linux in its turn is packaged in a form known as a Linux distribution. There are several Linux
distributions, both free and commercial.

ISU has a campus site subscription to Red Hat Enterprise Linux (RHEL), providing access for
university-owned equipment as well as personal access to students, faculty, and staff. All
our clusters are running RHEL.

The UNIX operating system


The UNIX operating system is made up of three parts; the kernel, the shell and the
programs.

The kernel
The kernel of UNIX is the hub of the operating system: it allocates time and memory to
programs and handles the filestore and communications in response to system calls.
As an illustration of the way that the shell and the kernel work together, suppose a user
types rm myfile (which has the effect of removing the file myfile). The shell searches the
filestore for the file containing the program rm, and then requests the kernel, through
system calls, to execute the program rm on myfile. When the process rm myfile has
finished running, the shell then returns the UNIX prompt % to the user, indicating that it is
waiting for further commands.

The shell
The shell acts as an interface between the user and the kernel. When a user logs in, the
login program checks the username and password, and then starts another program called
the shell. The shell is a command line interpreter (CLI). It interprets the commands the user
types in and arranges for them to be carried out. The commands are themselves programs:
when they terminate, the shell gives the user another prompt (% on our systems).

The adept user can customise his/her own shell, and users can use different shells on the
same machine. Most accounts on our clusters have the bash shell by default. The accounts
on hpc-class use shell specified at https://asw.iastate.edu/cgi-bin/acropolis/user/shell .

The bash and tcsh shells have certain features to help the user inputting commands.

Filename Completion - By typing part of the name of a command, filename or directory and
pressing the [Tab] key, the shell will complete the rest of the name automatically. If the
shell finds more than one name beginning with those letters you have typed, it will beep,
prompting you to type a few more letters before pressing the tab key again.

History - The shell keeps a list of the commands you have typed in. If you need to repeat a
command, use the cursor keys to scroll up and down the list or type history for a list of
previous commands.

Files and processes


Everything in UNIX is either a file or a process.

A process is an executing program identified by a unique PID (process identifier).

A file is a collection of data. They are created by users using text editors, running compilers
etc.
Examples of files:

 a document (report, essay etc.)

 the text of a program written in some high-level programming language

 instructions comprehensible directly to the machine and incomprehensible to a casual user, for example, a collection of
binary digits (an executable or binary file);

 a directory, containing information about its contents, which may be a mixture of other directories (subdirectories) and
ordinary files.

The Directory Structure


All the files are grouped together in the directory structure. The file-system is arranged in a
hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally
called root (written as a slash / )

In the diagram above, we see that the home directory of the undergraduate
student "ee51vn" contains two sub-directories (docsand pics) and a file
called report.doc.

What is UNIX?
UNIX is an operating system which was first developed in the
1960s, and has been under constant development ever since. By operating system, we
mean the suite of programs which make the computer work. It is a stable, multi-user, multi-
tasking system for servers, desktops and laptops.

UNIX systems also have a graphical user interface (GUI) similar to Microsoft Windows which
provides an easy to use environment. However, knowledge of UNIX is required for
operations which aren't covered by a graphical program, or for when there is no windows
interface available, for example, in a telnet session.

Types of UNIX

There are many different versions of UNIX, although they share common
similarities. The most popular varieties of UNIX are Sun Solaris, GNU/Linux, and MacOS X.
Linux in its turn is packaged in a form known as a Linux distribution. There are several Linux
distributions, both free and commercial.

ISU has a campus site subscription to Red Hat Enterprise Linux (RHEL), providing access for
university-owned equipment as well as personal access to students, faculty, and staff. All
our clusters are running RHEL.

The UNIX operating system


The UNIX operating system is made up of three parts; the kernel, the shell and the
programs.

The kernel
The kernel of UNIX is the hub of the operating system: it allocates time and memory to
programs and handles the filestore and communications in response to system calls.
As an illustration of the way that the shell and the kernel work together, suppose a user
types rm myfile (which has the effect of removing the file myfile). The shell searches the
filestore for the file containing the program rm, and then requests the kernel, through
system calls, to execute the program rm on myfile. When the process rm myfile has
finished running, the shell then returns the UNIX prompt % to the user, indicating that it is
waiting for further commands.

The shell
The shell acts as an interface between the user and the kernel. When a user logs in, the
login program checks the username and password, and then starts another program called
the shell. The shell is a command line interpreter (CLI). It interprets the commands the user
types in and arranges for them to be carried out. The commands are themselves programs:
when they terminate, the shell gives the user another prompt (% on our systems).

The adept user can customise his/her own shell, and users can use different shells on the
same machine. Most accounts on our clusters have the bash shell by default. The accounts
on hpc-class use shell specified at https://asw.iastate.edu/cgi-bin/acropolis/user/shell .

The bash and tcsh shells have certain features to help the user inputting commands.

Filename Completion - By typing part of the name of a command, filename or directory and
pressing the [Tab] key, the shell will complete the rest of the name automatically. If the
shell finds more than one name beginning with those letters you have typed, it will beep,
prompting you to type a few more letters before pressing the tab key again.

History - The shell keeps a list of the commands you have typed in. If you need to repeat a
command, use the cursor keys to scroll up and down the list or type history for a list of
previous commands.

Files and processes


Everything in UNIX is either a file or a process.

A process is an executing program identified by a unique PID (process identifier).

A file is a collection of data. They are created by users using text editors, running compilers
etc.
Examples of files:

 a document (report, essay etc.)


 the text of a program written in some high-level programming language
 instructions comprehensible directly to the machine and incomprehensible to a casual user, for example, a collection of
binary digits (an executable or binary file);
 a directory, containing information about its contents, which may be a mixture of other directories (subdirectories) and
ordinary files.

The Directory Structure


All the files are grouped together in the directory structure. The file-system is arranged in a
hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally
called root (written as a slash / )

In the diagram above, we see that the home directory of the undergraduate
student "ee51vn" contains two sub-directories (docsand pics) and a file
called report.doc.

50 Most Frequently Used UNIX / Linux Commands


(With Examples)
1. tar command examples
Create a new tar archive.

$ tar cvf archive_name.tar dirname/

Extract from an existing tar archive.

$ tar xvf archive_name.tar

View an existing tar archive.

$ tar tvf archive_name.tar

More tar examples: The Ultimate Tar Command Tutorial with 10 Practical Examples

2. grep command examples


Search for a given string in a file (case in-sensitive search).

$ grep -i "the" demo_file

Print the matched line, along with the 3 lines after it.

$ grep -A 3 -i "example" demo_text

Search for a given string in all files recursively

$ grep -r "ramesh" *

More grep examples: Get a Grip on the Grep! – 15 Practical Grep Command Examples

3. find command examples


Find files using file-name ( case in-sensitve find)
# find -iname "MyCProgram.c"

Execute commands on files found by the find command

$ find -iname "MyCProgram.c" -exec md5sum {} \;

Find all empty files in home directory

# find ~ -empty

More find examples: Mommy, I found it! — 15 Practical Linux Find Command Examples

4. ssh command examples


Login to remote host

ssh -l jsmith remotehost.example.com

Debug ssh client

ssh -v -l jsmith remotehost.example.com

Display ssh client version

$ ssh -V

OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003

More ssh examples: 5 Basic Linux SSH Client Commands

5. sed command examples


When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the
DOS file format to Unix file format using sed command.
$sed 's/.$//' filename

Print file content in reverse order

$ sed -n '1!G;h;$p' thegeekstuff.txt

Add line number for all non-empty-lines in a file

$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'

More sed examples: Advanced Sed Substitution Examples

6. awk command examples


Remove duplicate lines using awk

$ awk '!($0 in array) { array[$0]; print }' temp

Print all lines from /etc/passwd that has the same uid and gid

$awk -F ':' '$3==$4' passwd.txt

Print only specific field from a file.

$ awk '{print $2,$5;}' employee.txt

More awk examples: 8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR

7. vim command examples


Go to the 143rd line of file

$ vim +143 filename.txt


Go to the first match of the specified

$ vim +/search-term filename.txt

Open the file in read only mode.

$ vim -R /etc/passwd

More vim examples: How To Record and Play in Vim Editor

8. diff command examples


Ignore white space while comparing.

# diff -w name_list.txt name_list_new.txt

2c2,3

< John Doe --- > John M Doe

> Jason Bourne

More diff examples: Top 4 File Difference Tools on UNIX / Linux – Diff, Colordiff, Wdiff, Vimdiff

9. sort command examples


Sort a file in ascending order

$ sort names.txt

Sort a file in descending order

$ sort -r names.txt

Sort passwd file by 3rd field.


$ sort -t: -k 3n /etc/passwd | more

10. export command examples


To view oracle related environment variables.

$ export | grep ORACLE

declare -x ORACLE_BASE="/u01/app/oracle"

declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0"

declare -x ORACLE_SID="med"

declare -x ORACLE_TERM="xterm"

To export an environment variable:

$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0

System Calls in Unix and Windows


The interface between a process and an operating system is provided by system calls.
In general, system calls are available as assembly language instructions. They are also
included in the manuals used by the assembly level programmers.

Unix System Calls


System calls in Unix are used for file system control, process control, interprocess
communication etc. Access to the Unix kernel is only available through these system
calls. Generally, system calls are similar to function calls, the only difference is that they
remove the control from the user process.
There are around 80 system calls in the Unix interface currently. Details about some of
the important ones are given as follows -

System Call Description

access() This checks if a calling process has access to the required file
System Call Description

chdir() The chdir command changes the current directory of the system

chmod() The mode of a file can be changed using this command

chown() This changes the ownership of a particular file

kill() This system call sends kill signal to one or more processes

link() A new file name is linked to an existing file using link system call.

open() This opens a file for the reading or writing process

pause() The pause call suspends a file until a particular signal occurs.

stime() This system call sets the correct time.

times() Gets the parent and child process times

alarm() The alarm system call sets the alarm clock of a process

fork() A new process is created using this command

chroot() This changes the root directory of a file.

exit() The exit system call is used to exit a process.

Windows System Calls


System calls in Windows are used for file system control, process control, interprocess
communication, main memory management, I/O device handling, security etc. The
programs interact with the Windows operating system using the system calls. Since
system calls are the only way to access the kernel, all the programs requiring resources
must use system calls.
Details about some of the important system calls in Windows are given as follows -

System Call Description

CreateProcess() A new process is created using this command

ExitProcess() This system call is used to exit a process.

CreateFile() A file is created or opened using this system call.

ReadFile() Data is read from the file using this system call.

WriteFile() Data is written into the file using this system call.

CloseHandle() This system call closes the file currently in use.

SetTimer() This system call sets the alarm or the timer of a process

CreatePipe() A pipe is created using this system call

SetFileSecurity() This system call sets the security for a particular process

SetConsoleMode() This sets the input mode or output mode of the console’s input
buffer or output screen buffer respectively.

ReadConsole() This reads the characters from the console input buffer.

WriteConsole() This writes the characters into the console output buffer.

4.A Shell provides you with an interface to the Unix system. It gathers input from you and
executes programs based on that input. When a program finishes executing, it displays that
program's output.
Shell is an environment in which we can run our commands, programs, and shell scripts. There
are different flavors of a shell, just as there are different flavors of operating systems. Each flavor
of shell has its own set of recognized commands and functions.

Shell Prompt
The prompt, $, which is called the command prompt, is issued by the shell. While the prompt is
displayed, you can type a command.
Shell reads your input after you press Enter. It determines the command you want executed by
looking at the first word of your input. A word is an unbroken set of characters. Spaces and tabs
separate words.
Following is a simple example of the date command, which displays the current date and time −
$date
Thu Jun 25 08:30:19 MST 2009
You can customize your command prompt using the environment variable PS1 explained in the
Environment tutorial.

Shell Types
In Unix, there are two major types of shells −
 Bourne shell − If you are using a Bourne-type shell, the $ character is the default
prompt.
 C shell − If you are using a C-type shell, the % character is the default prompt.
The Bourne Shell has the following subcategories −

 Bourne shell (sh)


 Korn shell (ksh)
 Bourne Again shell (bash)
 POSIX shell (sh)
The different C-type shells follow −

 C shell (csh)
 TENEX/TOPS C shell (tcsh)
The original Unix shell was written in the mid-1970s by Stephen R. Bourne while he was at the
AT&T Bell Labs in New Jersey.
Bourne shell was the first shell to appear on Unix systems, thus it is referred to as "the shell".
Bourne shell is usually installed as /bin/sh on most versions of Unix. For this reason, it is the
shell of choice for writing scripts that can be used on different versions of Unix.
In this chapter, we are going to cover most of the Shell concepts that are based on the Borne
Shell.

Shell Scripts
The basic concept of a shell script is a list of commands, which are listed in the order of
execution. A good shell script will have comments, preceded by # sign, describing the steps.
There are conditional tests, such as value A is greater than value B, loops allowing us to go
through massive amounts of data, files to read and store data, and variables to read and store
data, and the script may include functions.
We are going to write many scripts in the next sections. It would be a simple text file in which
we would put all our commands and several other required constructs that tell the shell
environment what to do and when to do it.
Shell scripts and functions are both interpreted. This means they are not compiled.

Example Script
Assume we create a test.sh script. Note all the scripts would have the .sh extension. Before you
add anything else to your script, you need to alert the system that a shell script is being started.
This is done using the shebang construct. For example −
#!/bin/sh
This tells the system that the commands that follow are to be executed by the Bourne shell. It's
called a shebang because the # symbol is called a hash, and the ! symbol is called a bang.
To create a script containing these commands, you put the shebang line first and then add the
commands −
#!/bin/bash
pwd
ls

Shell Comments
You can put your comments in your script as follows −
#!/bin/bash

# Author : Zara Ali


# Copyright (c) Tutorialspoint.com
# Script follows here:
pwd
ls
Save the above content and make the script executable −
$chmod +x test.sh
The shell script is now ready to be executed −
$./test.sh
Upon execution, you will receive the following result −
/home/amrood
index.htm unix-basic_utilities.htm unix-directories.htm
test.sh unix-communication.htm unix-environment.htm
Note − To execute a program available in the current directory, use ./program_name

Extended Shell Scripts


Shell scripts have several required constructs that tell the shell environment what to do and when
to do it. Of course, most scripts are more complex than the above one.
The shell is, after all, a real programming language, complete with variables, control structures,
and so forth. No matter how complicated a script gets, it is still just a list of commands executed
sequentially.
The following script uses the read command which takes the input from the keyboard and
assigns it as the value of the variable PERSON and finally prints it on STDOUT.
#!/bin/sh

# Author : Zara Ali


# Copyright (c) Tutorialspoint.com
# Script follows here:

echo "What is your name?"


read PERSON
echo "Hello, $PERSON"
Here is a sample run of the script −
$./test.sh
What is your name?
Zara Ali
Hello, Zara Ali
$ Previous PageNext Page  

5. Difference between UNIX and Windows Operating System


UNIX : 

UNIX is a powerful, multi-user, and multitasking operating system originally


developed at AT & T Bell Laboratories. This operating system is very popular among
the scientific, engineering, and academic due to its most appreciated features like
flexibility, portability, network capabilities, etc. 

 Windows :

Microsoft window is a Graphical User Interface (GUI) based operating system that
provides graphical user-friendly alternatives for most of the command-line based
functions. Microsoft introduced a series of versions with the latest functions. 

Difference between UNIX and Windows Operating System

 UNIX : 

UNIX is a powerful, multi-user, and multitasking operating system originally developed at AT &
T Bell Laboratories. This operating system is very popular among the scientific, engineering, and
academic due to its most appreciated features like flexibility, portability, network capabilities,
etc. 

 Windows :

Microsoft window is a Graphical User Interface (GUI) based operating system that provides
graphical user-friendly alternatives for most of the command-line based functions. Microsoft
introduced a series of versions with the latest functions. 

Difference between UNIX and Windows Operating System : 


Here we will discuss the various differences between UNIX and Windows operating systems,
based on various parameters.
1. Licensing:

UNIX was developed as an open-source OS using C and Assembly languages. Since being open
source UNIX, and its various Linux distributions account for the most used OS in the world.
Unix and all its Linux distributions are available under the General Public License.

Windows Operating System is proprietary software owned by Microsoft, meaning its source
code is not available to the public.

2. User Interface:

Unix operating systems are relatively harder to grasp and produce significant barriers for
newcomers. However, some Linux distributions like Ubuntu are changing such perceptions by
bringing in more GUI-based applications.

Windows Operating System on the other hand is designed with the outset of keeping the UI as
simple and user-friendly as possible, so that non-IT people can easily use computers for their
work.

3. Processing:

UNIX operating system supports Multiprocessing, meaning many processes are executed


simultaneously. In Multiprocessing, every process has a separate address space and CPUs can be
added for increasing computing power.

Windows Support Multithreading, meaning many threads are created from a single process for
increasing computing power. In multithreading, many threads of a process are executed
simultaneously where common address space is shared by all the threads.

4. File System:

UNIX operating system uses STD.ERR and STD.IO file systems or the UFS (Unix File System)
and treats all physical drives as one logical drive. It has a robust and efficient file system. File
system is represented as a hierarchical tree under the same root.
Windows on the other hand, uses File Allocation Table (FAT32) and New Technology File
System(NTFS) systems for managing files and requires the owner of the executables before
executing, files store in folders on different data drive like, C,D,E.

GEEKSFORGEEKS
Difference between UNIX and Windows Operating System
In this article, we will be looking into the major difference between UNIX and
Windows Operating System.

 UNIX : 

UNIX is a powerful, multi-user, and multitasking operating system originally


developed at AT & T Bell Laboratories. This operating system is very popular among
the scientific, engineering, and academic due to its most appreciated features like
flexibility, portability, network capabilities, etc. 

 Windows :

Microsoft window is a Graphical User Interface (GUI) based operating system that
provides graphical user-friendly alternatives for most of the command-line based
functions. Microsoft introduced a series of versions with the latest functions. 

Difference between UNIX and Windows Operating System : 


1. Licensing:

UNIX was developed as an open-source OS using C and Assembly languages. Since


being open source UNIX, and its various Linux distributions account for the most
used OS in the world.  Unix and all its Linux distributions are available under the
General Public License.

Windows Operating System is proprietary software owned by Microsoft, meaning its


source code is not available to the public.

2. User Interface:

Unix operating systems are relatively harder to grasp and produce significant barriers
for newcomers. However, some Linux distributions like Ubuntu are changing such
perceptions by bringing in more GUI-based applications.

Windows Operating System on the other hand is designed with the outset of keeping
the UI as simple and user-friendly as possible, so that non-IT people can easily use
computers for their work.

3. Processing:

UNIX operating system supports Multiprocessing, meaning many processes are


executed simultaneously. In Multiprocessing, every process has a separate address
space and CPUs can be added for increasing computing power.

Windows Support Multithreading, meaning many threads are created from a single


process for increasing computing power. In multithreading, many threads of a process
are executed simultaneously where common address space is shared by all the threads.

4. File System:
UNIX operating system uses STD.ERR and STD.IO file systems or the UFS (Unix
File System) and treats all physical drives as one logical drive. It has a robust and
efficient file system. File system is represented as a hierarchical tree under the same
root.

Windows on the other hand, uses File Allocation Table (FAT32) and New
Technology File System(NTFS) systems for managing files and requires the owner of
the executables before executing, files store in folders on different data drive like,
C,D,E.

5. Users Accounts:

In the Linux system, there are three types of user accounts:


 Regular: These accounts have the moderate privilege to intended for routine
works, it can perform only the task for access only those files and services
for which it is authorized.
 Root: This account is the main user account of a Linux system, it has the
highest privilege to work administrative level work to manage all the
services. This is also known as superusers.
 Service: This account is generally used by services to run the process.

In Windows, there are three types of user accounts:

 Administrator: This account controls all the services and allows user to make
changes and check the activities of other users
 Child: This account comes with Family Safety settings which is assigned by
the admin.
 Guest: This account has no standard accounts with no privacy, it allows to
other people use your computer without being able to change PC settings and
install applications.

6. File Name Convention:

In Linux, we can save two files with the same name.

But in windows, we can not save with the same name. It generates errors:
7. Security:

UNIX is more secure by design. The primary protection on a Unix system is that
executing a “.exe” file is much more difficult. Here executables cannot be processed
without explicit permission as all processes in Unix are treated equally. But these are
slowly changing as Unix distributions are moving more towards GUI and now relying
on the application security itself. 

Another advantage of Unix systems is that getting rid of viruses is easier, as viruses
can only infect user accounts and the root remains intact and pure.

Windows is less secure in the sense that it is simple to execute files with minimal
permission. These can further lead to the installation of Malwares unknowingly on the
system.

8. Data Backup & Recovery:

In the earlier version of UNIX, salvaging data from a system when the device housing
the said data is inaccessible, was not possible. But in some distributions of Linux like
Ubuntu, a new feature is introduced called Live distribution can be used to recover
data from an inaccessible device.
Recovery and Backup of data in the Windows system are much simpler and can be
done using its inbuilt GUI for the same. It has an integration with OneDrive for data
backup and recovery too.

9. Case Sensitivity:

Unix is completely case-sensitive, meaning the files with names “GFG.txt” and
“gfg.txt” can be considered two different files. Windows, on the other hand, have
optional case sensitivity.

10. Hardware:

Hardware support is limited in UNIX systems. Some hardware might not have drivers
built for them. Windows has almost all the drivers for all the available hardware.

11. Reliability:

Unix is known for being very stable to run. Although the stability of Windows has
significantly improved in recent years, most Unix systems are still far superior in this
respect.

. Parameters UNIX Windows

1. Basic It is a command-based operating system. It is a menu based operating system.

It is an open-source system which can be It is a proprietary software owned by


2. Licensing
used to under General Public License. Microsoft.

It has a text base interface, making it harder It has a Graphical User Interface,
3. User Interface
to grasp for newcomers. making it simpler to use.

4. Processing It supports Multiprocessing. It supports Multithreading.

It uses Unix File System(UFS) that comprises It uses File Allocation System (FAT32)
5. File System
STD.ERR and STD.IO file systems. and New technology file system(NTFS).

It is more secure as all changes to the system


6. Security It is less secure compared to UNIX.
require explicit user permission.

7. Data Backup & It is tedious to create a backup and recovery It has an integrated backup and
Recovery system in UNIX, but it is improving with the recovery system that make it simpler to
. Parameters UNIX Windows

introduction of new distributions of Unix. use.

Hardware support is limited in UNIX system.


Drivers are available for almost all the
8. Hardware Some hardware might not have drivers built
hardware.
for them.

Although Windows has been stable in


Unix and its distributions are well known for
9. Reliability recent years,  it is still to match the
being very stable to run.
stability provided by Unix systems.

It is fully case-sensitive, and files can be


10. Case Sensitive It has case sensitivity as an option.
considered separate files.

You might also like