0% found this document useful (0 votes)
201 views

Vikrant Unix Notes

The document provides an introduction to Unix/Linux operating systems. It discusses that Unix is a multi-user, multi-tasking operating system that was initially developed in the 1960s and rewritten in C, enabling portability. The document outlines the basic components of Unix including processes, files, directories, shells, and permissions. It also summarizes some common Unix commands.

Uploaded by

Richa Mathur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
201 views

Vikrant Unix Notes

The document provides an introduction to Unix/Linux operating systems. It discusses that Unix is a multi-user, multi-tasking operating system that was initially developed in the 1960s and rewritten in C, enabling portability. The document outlines the basic components of Unix including processes, files, directories, shells, and permissions. It also summarizes some common Unix commands.

Uploaded by

Richa Mathur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Subject Name: Computer Programming V [Unix/Linux-Lab.

]
Subject Code: CS-5006
Semester: 5th
Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

Operating Systems

An operating system (OS) is a software that:


 manages the resources of a computer: CPU, memory, devices
 provides programmers and users with an interface to access those resources.
 may support/provide: multi-tasking, multi-users, GUI, security, etc.

Interfaces:

Application Program OS
User Hardware
User User Kernel

UNIX
Multi-user, multi-tasking OS, & open source.

A fully featured modern operating system (mostly coded in C) turns the computer into a useable
machine.

 It is available in a variety of “flavors.”


 It’s comprised of simple tools that perform a single function well.
 These tools can be used together to perform complex tasks.

 UNIX is trademarked by the Open Group


 To be called UNIX, an operating system must be certified as meeting the specification
(currently UNIX 03) by the Open Group
 Four UNIX's: Solaris (Sun), AIX (IBM), HP-UX (Hewlett-Packard), MacOS X Leopard
(Apple) [*note : All Unix's aren't the same. Each Unix usually developed its own
specialization]
 Unix refers to any of the “Unix-like” operating systems such as Linux, [
Open / Free/ Net ] BSD, or pre-Leopard MacOS X

Notes are by Vikrant sharma

Page no: 1 Follow us on facebook to get real-time updates from RGPV


Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

Unix provides a number of facilities

– management of hardware resources


– directory and file system
– loading / execution / suspension of programs

History

 1969 – Initial version by Thompson & Ritchie at AT&T Bell Labs.

 70’s – Rewritten in C (enables


portability).

 80’s – System-V (AT&T) and BSD


(Berkeley) versions.

 90’s – Linux by Linus Torvalds.

Unix is Made Up of
Processes
 Running Programs
User owned
System owned
Files
 Regular Files:
– Data
– Executables <-- usually start a process
 Directory Files
– Contain other files and directories
 Special Files

Notes are by Vikrant sharma

Page no: 2 Follow us on facebook to get real-time updates from RGPV


Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

Why Use UNIX?


 multi-tasking / multi-user
 lots of software
 networking capability
 graphical (with command line)
 easy to program
 portable (PCs, mainframes, super-computers)
 Free! (LINUX, FreeBSD, GNU)
 popular
 profitable 1996 Sales: US$34.5 Billion, up 12%
 not tied to one company
 active community

Unix Shell / Command Line


The shell is an interpreter used to communicate with the OS interactively on the command line.

A shell is a process that acts as an interface to the OS. It allows


Unix
user toShell
run pr the user to run programs individually and together to accomplish
a task.
task. a task.
• Common Shells: Bourne shell, the C shell, and the Korn shell.
 The shell on bingsuns is tcsh (tc shell).
 Users can switch between shells, using the commands bash, csh,
ksh, sh.
 Control D (^d) to return back to original shell, or just use the
command: exit.

• After a successful login, the shell program is run. The default shell of bingsuns: tcsh
• It displays like this :-
PID TTY TIME CMD
2159 pts/2 0:00 tcsh

Notes are by Vikrant sharma

Page no: 3 Follow us on facebook to get real-time updates from RGPV


Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

Basic commands in Unix shells

Command Short explanation


ls -l prints the content of a directory
pwd prints the name of the current directory
cd change directory
mkdir creates a new directory
cp copies a file [cp sourcefile destinationfile]
mv moves a file/directory
rm removes (deletes) a file
rmdir removes an empty directory
man help (manual) on a command
cat Merge files [cat File1 File2]
who Show who are login
who am i Identify the current user
date shows date & time
cal calender
touch creates an empty file [ex: touch file1.txt]

Notes are by Vikrant sharma

Page no: 4 Follow us on facebook to get real-time updates from RGPV


Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

Unix File system

/ (root)

unix bin usr dev temp lib etc


p
User1 User2 User3 bin

Directory Contains
bin Binary executable files
lib Library functions
dev Device related files
etc Binary executable files usually required for system administration
tmp Temporary files created by unix or users
usr Home directories of all users
/usr/bin Additional binary executable files

Notes are by Vikrant sharma

Page no: 5 Follow us on facebook to get real-time updates from RGPV


Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

User management

Once user login a unique UID (user identification) is assigned


User may belongs to one or more groups identified by GID (group identification)

System administrator (root)

Group1 Group2 Group3

User1 User2 User6 User7

User3 User4 User5

Notes are by Vikrant sharma

Page no: 6 Follow us on facebook to get real-time updates from RGPV


Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

File permissions

r – Read contents [no assign is 4]


w –Modify (write) contests [no assign is 2]
x – Permission for execution (if executable) [no assign is 1]

d –Shows it is directory

* Total 9 bits are assigned to a file (i.e.2-10 bits, 1st bit for showing whether it is directory)

Permissions = bits 2-10


 bit 1 = is a directory (d)

 first three bits 2,3,4: user owner permissions(U)


 bits 5,6,7: group permissions(g)
 bits 8,9,10: other permissions(O)

Examples:

 Assigning permission to file


chmod o=r file.txt
where o for other & r for read

 Removing permission to file


chmod u-w file.txt
where u for user owner & w for write

 chmod 754 file.txt

(U) (O)
(g)

So in above example : permission to user owner = 7 = 4+2+1 = rwx


Group = 5 = 4+1 = rx
Other = 4 = r

Notes are by Vikrant sharma

Page no: 7 Follow us on facebook to get real-time updates from RGPV


Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

Editing text files in Unix

 Common text editors:


 pico - simple but very basic, similar to notepad
 vi, vim
 emacs, xemacs (GUI)

To open a file in vi editor run the command: vi filename

To write or modify something in file go to Insert mod by pressing anyone of three keys a/i/o

After writing in file following modes for quit from editor


First press “Escape” key then:
:q! for quit without saving
:wq for save & quit

Program & Process

• Program is an executable file that resides on the disk.


• Process is a program in execution. it is an active entity.
• A Unix process is identified by a unique non-negative integer called the
process ID (PID).
• Check process status using the “ps” command.

Command Short explanation


ps Process status
Ps -aux Show prosses of all terminals
Ps-au Processes & usernames
Ps-a Show all prosesses

Kill : to kill process Ex. “ Kill –term5467 ” where term is prosess name
& 5467 is PID.

Notes are by Vikrant sharma

Page no: 8 Follow us on facebook to get real-time updates from RGPV


Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

Guidelines to Students

How to Run Shell Scripts

There are two ways you can execute your shell scripts. Once you have created a script file:

Method 1
Pass the file as an argument to the shell that you want to interpret your script.

Step 1 : create the script using vi, ex or ed

For example, the script file show has the following lines

echo Here is the date and time


date

Step 2 : To run the script, pass the filename as an argument to the sh (shell )

$ sh show
Here is the date and time
Sat jun 03 13:40:15 PST 2006

Method 2:
Make your script executable using the chmod command.

When we create a file, by default it is created with read and write permission turned on and execute permission
turned off. A file can be made executable using chmod.

Step 1 : create the script using vi, ex or ed

For example, the script file show has the following lines

echo Here is the date and time


date

Step 2 : Make the file executable

$ chmod u+x script_file


$ chmod u+x show

Step 3 : To run the script, just type the filename

$ show
Here is the date and time
Notes are by Vikrant sharma

Page no: 9 Follow us on facebook to get real-time updates from RGPV


Downloaded from be.rgpvnotes.in

Introduction to Unix/Linux

Sat jun 03 13:40:15 PST 2006

How to run C programs

Step 1 : Use an editor, such as vi, ex, or ed to write the program. The name of the file containing the program
should end in .c.

For example, the file show.c contains the following lines :

main()
{
printf(“ welcome to CDGI “);
}

Step 2 : Submit the file to CC ( the C Compiler )

$ cc show.c

If the program is okay, the compiled version is placed in a file called a.out

Step 3 : To run the program, type a.out

$ a.out

Welcome to CDGI

Notes are by Vikrant sharma

Page no: 10 Follow us on facebook to get real-time updates from RGPV


We hope you find these notes useful.
You can get previous year question papers at
https://qp.rgpvnotes.in .

If you have any queries or you want to submit your


study notes please write us at
[email protected]

You might also like