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

7. Linux Basics

The document provides a comprehensive overview of UNIX structure and file system, detailing components like the kernel, shell, and various commands. It explains the hierarchical organization of files and directories, the types of files, and the importance of partitions, particularly the swap partition for memory management. Additionally, it covers internal and external commands, working with links, and various shell operations and commands used in UNIX.

Uploaded by

Palak Jaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

7. Linux Basics

The document provides a comprehensive overview of UNIX structure and file system, detailing components like the kernel, shell, and various commands. It explains the hierarchical organization of files and directories, the types of files, and the importance of partitions, particularly the swap partition for memory management. Additionally, it covers internal and external commands, working with links, and various shell operations and commands used in UNIX.

Uploaded by

Palak Jaiswal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

LINUX BASICS

UNIX STRUCTURE

A file system is a logical collection of files on a partition or disk. A partition is a container for information
and can span an entire hard drive if desired. One file system per partition allows for the logical
maintenance and management of different file system. Everything in UNIX is considered to be a file.
The main concept that unites all versions of UNIX is the following: -
1. Kernel: The kernel is the heart of the operating system. It interacts with hardware and most of
the tasks like memory management, task scheduling and file management.
2. 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 most famous shells
which are available with most of the UNIX variants.
3. Commands and Utilities: There are various command and utilities which you would use 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 optional options.
4. Files and Directories: All data in UNIX is organized into files. All files are organized into
directories. These directories are organized into a tree-like structure called the file system.

The operating system can be divided into four parts:


1. File System: It is a collection of files stored on a disk. File is the fundamental unit of the UNIX.
2. Scheduler: It is a program that allows more than one user to use the computers at the same
time. It shares the computer resources among all the user.
3. Pipes: UNIX allows to link commands together using a pipe. The pipe acts as a temporary file
which only exists to hold data from one command until it is read by another.
4. Shell: It is the system’s command interpreter. It is a program that reads the line at the terminal
and perform various operation depending on that.
FILE SYSTEM
UNIX uses a hierarchical file system structure with root ( / ) at the base of the file system and all other
directories spreading from there. A UNIX file system is a collection of files and directories that has the
following properties:
➢ It has a root directory that contains other files and directories.
➢ Each file or directory is uniquely identified by its name and a unique identifier called an inode.
➢ By convention, the root directory has an inode no of 2 and the lost+found directory has an inode
no 3. Inode no 0 and 1 are not used.
➢ It is self-contained, there are no dependencies between one file system and any other.

The UNIX file id dived into three types:


1. Ordinary Files: These are documents, programs source code or program data. Executable
binary files or computer programs are also considered as ordinary files. Each file has following
attributes: -
a. File name
b. Size in bytes
c. Time of last change
d. Set of access permission
e. An owner and a group
f. Inode no
2. Special Device Files: Each physical device on the system is assigned to a special file. These
are hard disk, floppy disk, terminal, printer, system memory. It is of two types:
a. Block Mode: 1 block of data is accesses at once. Cannot access less than 1 block
(512/1024 bytes). Ex hard disk, floppy disk.
b. Character Mode: 1 Character at a time. Ex terminal
3. Directory Files: A directory contains the names and inode no of the files within it. Use of inode
internally to organize file system. Inode contain information about files.

The UNIX has two types of accounts Super user account and User account. A user account must be
created by super user. A user account has following information: - login name, password, group
identification, home directory and login shell. The directories have specific purposes and generally hold
the same type of information for easily locating files. The directories are:
DIRECTORY DESCRIPTION
/ This is the root directory.
/bin Here all executable files are located. They are available to all users.
/dev Here device drivers are located.
/etc Contains various commands & files which are used for system administration.
/lib Contains shared library files.
/boot Contains files for booting the system
/home Contains the home directory for users and other accounts.
/mnt Used to mount temporary file system such as cd rom, floppy disk.
/tmp Hold temporary files used between system boot and other uses.
/usr It contains other directories. Among these are home directory for each user.
/var Typically contains variable length files such as log and print files.
/proc Contains all processes marked as a file by process no or dynamic information.
/sbin Contains binary executable files, usually for system administration.
/kernel Contains kernel files (core of UNIX system)
The UNIX disk is divided into four logical parts:
BLOCK BOOT SUPER BLOCK INODE LIST DATA BLOCK

✓ In block boot bootstrap program is kept.


✓ Super block contains the global information i.e. about the file system, how many inode is empty
or full, how many data block is empty or full.
✓ Inode is dedicated to one file and contains information of file. Each inode has a no. This no is
used to look up an entry in the inode table which gives information on the type, size and location
of the file and the user id of the owner of the file.
✓ Data blocks contains actual data.

Inode contains information of file except the data. The things are:
✓ Owner
✓ Size
✓ Permission
✓ No of link
✓ File type
✓ Date last modified
✓ Date last accessed
✓ Date last inode changed
✓ Disk address of data

DISK ADDRESS OF DATA


1. It has 13 pointers.
2. First 10 used to point to data block.
3. 11 no is used to point a block which is divided into 256 parts for 256 pointer address.
4. 12 no is used to point a block of 256 parts but after that each part of 256 points to a block of 256
pointer.
5. 13 no is same as 12 but each part of 256 points to a block of 256 pointers.
Total no of address: 10+256+256*256+256*256*256 = 16843018

MULTIPLE FILE SYSTEM


Logically hard disk is partitioned. For multiple file system, then each partition is treated as a disk and
each partition has its own disk file and its own tree structure.
✓ Each disk has root file system
✓ One disk gets joint to other, when UNIX starts. This joint is called mounting and from where they
are joined is called mount point.
✓ There are many file systems and mounted each as UNIX loads.
✓ Root file system automatically mounted and another disk get mounted then. After mounted they
are one.

WHAT IS KERNEL? EXPLAIN THE TASK IT PERFORMS.


Kernel is used in UNIX like systems and is considered to be the heart of the operating system. It is
responsible for communication between hardware and software components. It is primarily used for
managing the systems resources as well. The Kernel Activities:
The Kernel task manager allows tasks to run concurrently.
✓ Managing the computer resources: Kernel allows the other programs to run and use the
resources
✓ Resources include I/O devices, CPU, memory.
✓ Kernel is responsible for Process management. It allows multiple processes to run
simultaneously allowing user to multitask.
✓ Kernel has an access to the systems memory and allows the processes to access the memory
when required.
✓ Processes may also need to access the devices attached to the system. Kernel assists the
processes in doing so.
✓ For the processes to access and make use of these services, system calls are used.

HOW THE EXTERNAL AND INTERNAL COMMANDS ARE DIFFERENT IN UNIX


Internal commands are something which is built into the shell. For the shell built in commands, the
execution speed is really high. It is because no process needs to be spawned for executing it. For
example, when using the "cd" command, no process is created. The current directory simply gets
changed on executing it. External commands are not built into the shell. These are executable present
in a separate file. When an external command has to be executed, a new process has to be spawned
and the command gets executed. For example, when you execute the "cat" command, which usually
is at /usr/bin, the executable /usr/bin/cat gets executed.

WHY WE NEED PARTITIONS IN LINUX? EXPLAIN SWAP PARTITION


Disk partitioning is the creation of separate divisions of a hard disk drive using partition editors such as
fdisk. Once a disk is divided into several partitions, directories and files of different categories may be
stored in different partitions. Many new Linux sys admin (or Windows admin) create only two partitions
/ (root) and swap for entire hard drive. A "swap" partition is a piece of your disk storage dedicated to
handling Random-Access Memory overflow conditions, with the intent of making your computer more
capable. This is common to all UNIX systems. UNIX divides its physical RAM into chucks of memory
called pages. Swapping is the process whereby a page of memory is copied to the preconfigured space
on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical
memory and the swap space is the amount of virtual memory available. Swapping is necessary for two
important reasons. First, when the system requires more memory than is physically available, the kernel
swaps out less used pages and gives memory to the current application (process) that needs the
memory immediately. Second, a significant number of the pages used by an application during its
startup phase may only be used for initialization and then never used again. The system can swap out
those pages and free the memory for other applications or even for the disk cache.

WORKING WITH LINK


✓ Link is a connection between an inode no and the filename associated with it.
✓ Command to create link is ln
✓ Link is of two type –
o Hard Link: only ordinary file
o Symbolic Link: Soft Link
✓ $ln aa.txt bb.txt: - Now bb.txt is another name of aa.txt (hard link)
✓ $ln –s aa.txt bb.txt: - Now another file bb.txt is created and have address of aa.txt
✓ Directories cannot be linked.
✓ Cross device link (link across the file system) is not possible.
✓ All device files have no size. In place of size, it comes with two integer no separated by comma.
Ex 1, 1. First no is a major device no and second one is minor device no.
✓ Major device no gives us what type of device.
✓ Minor device no gives us individual instance of a device.
✓ In /dev directory, there are two special files (devices).
o /dev/tty: Indicated a terminal
o /dev/NULL: File is present but not present also. Data stored in this get destroyed as the
end of file is stored at the beginning of the file.

COMMANDS
✓ pwd: give the current path (Present Working Directory). Single dot: current directory & two dot:
parent directory.
✓ date: give current date and time
o -u: display the date in Greenwich mean time
o mm: is the month no
o dd: is the day no in the month
o HH: is the hour no in 24 hr. format
o MM: is the minute no
o cc: is the century minus one
o YY: last 2 digits of the year no.
✓ cal: calendar of current year. If particular moth and year the $cal 8 2017
✓ who: shows no of user currently logged in.
✓ who am i: exclusively that terminal where that command is given.
✓ ps: show process no
✓ clear: clear the screen
✓ echo: print the message after that echo
✓ man: help
✓ bc: calculator
✓ mkdir: creates a directory
✓ rmdir: removes the empty directory
✓ mv: rename directory / file
✓ cp: copy a file. –i: interactive option.
✓ rm: remove files & Use –i for option.
✓ cd: change directory
✓ ls: directory Listing
o -a: list all entries including those that begin with dot & two dot.
o -d: if an argument is directory, list only its name.
o -l: list in long format
o -n: same as l except owner’s UID and group GID are printed.
o -x: output in multiple columns
o -r: sort filename in reverse order
o -i: display inode no
✓ ls –l output
_ permission no_of_link owner size date_last_mofified name
_: type of file (d-directory file, b-block mode device, c-character mode device, - : ordinary file)
No of user: - 1) Owner (u) 2) Group (g) 3) Others (o)
Permission: - 1) Read (r) 2) Write (w) 3) Execute (x)
Format of permission: r w x rwx r w x : first is user then group and last others
✓ ls > list: Directing output to a file
✓ lc: listing in column wise
✓ wc: counting no of lines in a file. It has three values: first no of lines then words and then
character. Also –c for character only, -l for line and –w for word only.
✓ rm *: removes all files without giving warning.
✓ echo *: shows all file of current working directory
✓ cat: it took the input and send to standard output.
o >: output redirection
o <: input redirection
o cat > filename: took input and store in the file.
o cat < filename: display the content of file.
o -v: display non printing character
✓ sort: it took the input from standard input and then sort the input and show in standard output. It
takes all as ASCII character.
✓ more: paging output. Ex ls | more. Use pipe
✓ write <username>: communicate b/w user. To stop ctrl+d. user shoul be online.
✓ mesg n/y: block getting message, n- stop message getting, y- begin message getting
✓ mail <username>: sending mail offline or online
✓ mail: reading mail
✓ grep <pattern> <filename>: search for pattern in the file and shows the line where the pattern
appears. –v option can be used. It shows the line where pattern does not appear.
✓ chmod: change permission to a filename. + is used for granted and – is used for withdraw. Ex.
Chmod ugo+x filename. Permission can be given in octal mode also. Ex $chmod 777 filename.
Where first is for owner, then group and last other. The values is calculated as read (4), write
(2), and execute (1).
✓ passwd: changing your password
✓ cmp file1 file 2: compare two files byte by byte and the location of first mismatch is echoed.

WORKING WITH SHELL


One shell can be put over the parent shell
$ : Bourne Shell, parent shell
$ksh : Korn Shell is put over Bourne Shell
$^d : Korn Shell is destroyed and return to Bourne Shell
$^d : Gives error as parent shell cannot be destroyed

Ex:
$x=2
$echo $x
2
$sh
$echo $x : x not defined here, parent shell variable is not transferred to child shell
$y=3
$echo $y
3
$^d : child shell destroyed
$echo $y : y not found as child shell is destroyed and all its variables.
Parent shell variable can be shown in child by using “export” keyword.
$x=2
$export x: x is copied to child shell
$sh
$echo $x
Each running program has exit status. When a program (running) ends, it returns a integer no to OS. If
returned 0, then successfully finished. If returned other than 0 then the program if finished
unsuccessfully.

FILTER COMMAND
It transforms and show the content of the file.
➢ sort <filename>: Sort, merge and remove repeated lines with sort
➢ pr <filename>: to format text to provide margins and headers, double spacing and multiple
column output
➢ | -> Ex ls|pg
➢ more: first one page and then one line by one.
➢ head: pickup lines from the beginning
➢ tail: pickup lines from the end
➢ cut: extract characters or field (vertically), range can be given using hyphen
➢ paste: join two files laterally and multiple lines to a single line.
Ex. dept.lst
01|account|6213
03|progs|5423
05|marketing|6521
04|production|9876
02|sales|1006
✓ $ pr dept.lst
✓ $ head –n 3 dept.lst
✓ $ tail –n 3 dept.lst
✓ $ cut –c 1-2 dept.lst use this if column width is same for every column
✓ $ cut –d \| -f 2,3 dept.lst -d for delimiter (default tab) and –f for field list
✓ $ cut –d \| -f 2,3 dept.lst | tee cutlist1 tee facilitate that saves the output to file.
✓ $ cut –c 1-2 dept.lst | tee cutlist2
✓ $ paste cutlist1 cutlist2 default is tab b/w then
✓ $ paste –d”|” cutlist1 cutlist2 default is then “|”
✓ Sort dept.lst
✓ Sort –t”|” –k 2 dept.lst sort on second column and specify default separation
✓ Sort –t”|” –r –k 2 dept.lst same as above but in reverse i.e. descending

You might also like