Вы находитесь на странице: 1из 17

UNIX

- THE FIRST EDITION OF UNIX WAS CREATED IN 1969


- THAT EDITION WAS CREATED BY THE KEN THOMPSON & DENNIS RITCHIE
IN BELL LABS.

PRINCIPLES OF UNIX

1 EVERTHING IS FILE INCLUDING THE HARDWARE.


2. CONFIGRATION DATA IS STORED IN SIMPLE TEXT FILE.
3. SMALL & SINGLE PURPOSE PROGRAMMS
4. ABILITY TO CHAIN THE PROGRAM
5. IT IS OPEN SYSTEM. MEANS,
i run for any reason
ii redistribute to the neighbors
iii freedom to improve
6. MULTI–USER, MULTI–TASKING
7. NOTHING IS AUTO–EXCUTABLE
8. SYSTEM SECURITY.

HOW ACTUALL Y OPERATING WORKS?

As you know each operating system has minimum three parts which are hardware, Kernel &
shell.

HARDWARE: – All the peripherals which are present inside your system (Processor,
Motherboard, RAM, etc) all are comes under the hardware.

KERNEL: – UNIX kernel is the heart of the Operating system. It is the master program
which controls the computer’s resources, allots them to users and to different task.
SHELL: –UNIX shell is the command interpreter for the commands input by the user. Each
user has its own shell; multiple users may not be having the same shell.
Functions of shell
A It acts as the command interpreter between the user & hardware (Kernel).
B It expands the various meta characters used in file operations
C It is responsible for the redirection output of one command as the input for
the other.
D It is responsible for executing the shell scripts which uses the
programming language. (Commands)
E It is responsible to setting the environment for the user.

LINUX

- THE FIRST KERNEL OF LINUX WAS FINNISHED BY COLLEGE


STUDENT.
- STUDENT NAME WAS LINUS TORVALDS
- LINUX WAS PUBLISHED BY NEWSGROUP IN AUG, 1991.

FEATURES OF LINUX
1. IT IS AN UNIX LIKE OPERATING SYSTEM
2. IT HAS WIDE HARDWARE SUPPORT
3. IT HAS SUPPORT FOR SMALL AS WELL AS LARGE APPLICATION
4. IT SUPPORTS MANY NETWORKING PROTOCOLS & CONFIGRATIONS
5. IT HAS SIX VIRTUAL CONSOLE (ALT+F(1–6)) & ONE GRAPHICAL
CONSOLE ON (ALT+F7)

XORG GUI FRAMEWORK

1. MODERN, FREE IMPLEMENTATION OF XFREE86


2. HIGHLY FLEXIBLE FRAMEWORK FOR DISPLAYING GRAPHICAL
APPLICATIONS AND ENVIRONMENTS
3. COMPLETELY NETWORK–TRANSPARENT CLIENT/SERVER ARCHICTURE
4. SYSTEM CAN BE CONFIGRED TO PRESENT A GRAPHICAL LOGIN SCREEN
ON CTRL–ALT–F7
XORG GRPHICAL ENVIOREMENT

TWO TYPES OF ENVIOREMENT ARE PRESENT IN GUI (GRAPHICAL USER


INTERFACE) MODE

1. GNOME(GRAPHICAL NETWORK OBJECT MODEL ENVIREMENT)


a. THE DEFAULT DESKTOP ENVIREMENT
b. ALSO THE USERFRIENDLY
c. IT HAS THE PANEL ALONG THE BOTTOM OF THE SCREEN WITH THE
LAUNCHING APPLICATIONS & DISPLAYING INFORMATION.

2. KDE(K DESKTOP ENVIOREMENT)


a. IT ALSO THE ANOTHER RUSERFRIENDLY ENVIOREMENT
BASIC COMMANDS
1. ls – to see the list of the files & directories in that directory
ls <options> <directory>
–l long listing
–a all files including hidden files
–d directories only
–i inode no
–h human readable (1MB=1024bytes)
–H human readable (1MB=1000bytes)

2. touch –to create a blank file & to modify the date & time of file & directory
touch <filename (the file should be in the working directory only)>

3. cat – to see the contents of file


cat <filename with full path>

cat > – to write the data into text file


cat > <filename>

cat >> – to see the append to file


cat >> <filename>

4. head – to see the first 10 lines of file


head <filename with full path>

5. tail – to see the last 10 lines of file


tail <filename with full path>

6. more – to see the file content in page wise format


more <filename with full path>

7. wc – to count the lines, words & letters of the file


wc <filename with full path>
–l for lines only, –w foe words only, –c for characters only

8. mkdir – to create a new directory


mkdir <new directory name> –to create the directory in the working directory
mkdir <full path followed by the new directory name> –to create the directory
anywhere

9. cd – to change the directory


cd <directory name>
cd . . <enter> to go to the parent directory
cd <enter> to go to home directory from anywhere

10. pwd –to see the present working directory

11. cp – to copy the files & directories


cp <options> <destination full path> <source full path>
–r recursively
–f forcefully
12. mv – to move the files & directories
mv <source> <destination>

13. rmdir –to remove an empty directory


rmdir dir name

14. rm –to remove a regular file


rm –rf –to remove the directory with its content

15. date –to see the current date & time


date
date <MONTHDATEHOURSMINUTESYEAR.SECOUNDS> –to change the date &
time
date 031413402009.35

16. cal – to see the current month’s calendar


cal <month> <year>
cal <year>

17. find –to search the files and directories


find <location> –name <filename>

18. who to see the information about the users logon to local machine

19. hoami to see the information about yourself

HELP COMMANDS TO GET THE INFORMATION ABOUT ANY COMMAND


FROM SYSTEM –

1. man <command>
2. info <command>
3. <command> ––help
4. whatis <command>
5. In GUI mode the help application is present inside the panel in the start menu

BROWSING THE FILESYSTEM

The Red Hat Enterprise Linux has the hierarchy structure for the file system.
In the RHEL each and every file’s address start from only the “/”.(slash )
Like Window in RHEL also some system directories are made from system side at the time
of installation like,
/boot : – Kernel & booting related files
/bin : – Binary files related to user
/dev : – Storage device related files
/etc : – Configuration files
/home : – home directory for all the users
/lib : – Library files
/media : – By default mount point for the removable storage when you mount
from GUI mode
/misc : – Miscellaneous files
/mnt : – Mount point for the removable storage
/opt : – Mount point for the removable storage
/proc : – System information (Hardware)
/root : – Home directory of user root (Administrator)
/sbin : – Binary files related to system
/selinux : – Selinux related (Security enhanced Linux like firewall)
/srv : – Server related
/sys : – System information only used by the system only
/tmp : – Application & user buffer
/usr/bin : – User related binary files
/usr/sbin : – System related binary files
/usr/share : –Sample configuration files
/var : –Variable files

As you all know in Red Hat we do our maximum on the console (command prompt) so we
do not have the icons and pictures from where we will know which one is file or directory.
For that we use the command ls –l which gives us the output like,

drwxr–xr–x 2 root root 4096 Oct 14 00:26 directory


–rw–r––r–– 1 root root 40 Oct 14 00:50 file

In the above case you will some different characters at the starting, from where you will
the kind of file.

- –stand for ordinary file


d –stand for directory file
l –stand for link file
c –stand for character file
b –stand for block special file

BASH SHELL

As you know the role of shell in system, you also know that every user has its own shell.
There are many shells present in your system like,
/bin/bash, /bin/ksh, /bin/csh, /sbin/nologin, etc.
But the most of the work is done on the Bash shell & it is also the by default shell.

Features of Bash shell


1. Command completion
2. Command line editing
3. Use of various meta characters
4. History

STANDERED I/O & PIPES

One of the most important features of Linux is the streaming nature of data known as
standard input, standard output & standard error. This allows the input from program to
come from any source and the output to go to any source.

Linux provides three I/O channels to processes


Standard input : keyboard is default
Standard output : terminal window is default
Standard error : terminal window is default

Common redirection operators: –


> Command > file Directs standard output of command to file
>> Command > file Appends standard output of command to file
< Command < file Command receives the input from file
2> Command 2> file Error messages from command are directed
to file
2>> Command 2>> file Error messages from command are
appended to file

PIPES: –

Two of the basic tenets of UNIX philosophy are make small programs that do thing well and
expect the output of every program to become the input to another.

Command1 | Command2

Any command that writes to standard output can be used on left–hand side of a pipe.
Any command that’s read from standard input can be used on the right–hand side.
Multiple commands can be chained together with pipes.

VI editor: –

The vi is standard editor under Linux & Unix systems. And the newer vim editor is improved
editor, standard Red Hat editor.

To start vi,
vi <filename> If the filename exists, the file is opened the content are displayed, If file does
not exist it creates the file when the edits are saved for first time.

Some useful options,


vi –m myfile file is non–modifiable
vi –R myfile file is only modifiable by using the exclamation point :w!
vi –n myfile do not use the swap file for backup
vi –r myfile recover data from a swap file after a crash
vi –x myfile encrypt file when saving, decrypt file when editing

VI editor work in three modes,


1. Insert mode
2. Command mode
3. Ex mode

In Insert mode, your keystrokes are actually data entered into your document rather than
commands.

In command mode you will get to do the actions like cursor movement , change, delete,
yank(copy), put & search.
In final ex mode, you will going to do configuring, exiting, saving, search and replace.

Entering Insert Mode

a append after the cursor


i insert before the cursor
o opens a new line below
A append to end of line
I Insert at beginning of line
O opens a new line above

Leaving Insert mode :<esc>

Command mode

Change Delete Yank(copy)


Line cc dd yy
Letter cl dl yl
Word cw dw yw

ndd deletes the “n” number of lines, Any number can be precede any of the change, delete, and
yank or put commands.

Use p or P to put (paste) copied or deleted data


p puts line data below the cursor
P puts line data above the cursor
p puts character data after the cursor
P puts character data before the cursor

Undoing changes
u undoes most recent change
<ctrl–r> redo last undone change
EX MODE: –

:w to save the changes


:q to quite without saving
:wq to save & then quiet
:w! to save changes forcefully
:wq! to save & then quiet forcefully

USER MANAGEMENT: –

User: –The application or service or resource which controls the system in efficient manner
with some authentication process is user. There are three types of user,

Administrator (root) (UID=0)


Super
Normal (UID=500+)

Group: –If we want give the same permissions or rights to multiple user, we create a group of
that users, to decrease the administrator load.
There are two types of group

Primary
Secondary

1. useradd: –to create a new user


useradd <options> <username>
–d home directory
–c comment
–s shell
–g gid or primary group
–G secondary group
–u uid
–m to create a new home directory

2. usermod: – to modify an existing user


usermod <options> <exist username>
–d home directory
–c comment
–s shell
–g gid or primary group
–G secondary group
–u uid
–m to create a new home directory
–l login name

3. passwd: – to change the user password


passwd <username> ––only for the user root
passwd
4. cat /etc/passwd: –to see the total information about all the system users. The entry
will be,

root:x:0:0:root:/root:/bin/bash

Where root is username, x stand for the link to shadow file, 0 is stand for UID, 0 is stand
for GID, root is stand for the comment, /root is the home directory, /bin/bash is the shell
of that user.

5. cat /etc/shadow: – to see the encrypted password for the entire user.

root :< encrypted password>

Where root is username, after colon (:) everything is encrypted password.

6. userdel: –to delete a particular user.


userdel <username>
userdel –r <username> to delete the user with its home directory.

7. groupadd: – to add a new group.


groupadd <group name>

8. groupmod: –to modify the existing group


groupmod <options> <existing group name>
–g gid
–n to change the group name
9. groupdel: –to delete the group.
groupdel <exist group name>

9. cat /etc/group: – to see the list of all groups on that local machine with all the
members.
group: x:503:usera, userb

Where ‘group’ is group name, ‘x’ is the link to the shadow file, 503 is gid and
usera & userb are the members of that group.

Users, groups & permissions

As all you know is, Linux has one of the most powerful features as secure
operating system. So to keep that, we need to implement some permission on files & directories.
There are three modes of file accessing,
a. Read only
b. Write
c. Execute

And there are three categories to divide the permissions,


a. User or owner
b. Group owner
c. Other
You can see the permissions of file & directory with the help of command “ls –l”
You will get output like,
drwxr–xr–x 2 root root 4096 Oct 14 00:26 directory
–rw–r––r–– 1 root root 40 Oct 14 00:50 file

By default permission for any file or directory in Linux is,


File –rw–rw–rw & for directory drwxrwxrwx.

But as you know Linux is secured operating system so you have to give permissions as per
requirement & as per the security concern. So in Linux, by default we need to remove
permissions from file & directory. For that we set user mask to assign by default permission,
umask is the command with you can see the user mask of particular user & also you can set
the user mask.
By default umask of user root is 0022 & for normal user it is 0002.
So now default permission for any file or directory will be,
Default permissions – umask.

1. ls –l : – to see the permissions for file.

drwxr–xr–x 2 root root 4096 Oct 14 00:26 directory


rw–r––r–– 1 root root 40 Oct 14 00:50 file

In this example you are getting 10 permissions which you have to divide
in 4 categories which will be like follows
d | rwx | r–x | r–x
special owner group other
permissions owner

2. chmod: – to change the permissions


there are two methods to change the permission,
Numerical

In numeric methods permissions are assigned with help of no’s.


Read=4
Write=2
Execute=1
Special permissions=0

To change the permissions we require giving the command in the following syntax.
chmod <permissions which you have to assign in no’s> <filename with full path>
EX. chmod 0777 /home/user1/test/

Symbolic

In symbolic method you have to assign the permissions with the help of characters.
User or owner =u Read=r
Group owner=g Write=w
Other=o Execute=x

To change the permission we require giving the command in the following syntax
EX. chmod u+w,g+w,o+r /home/user1/test
“+” is used to add the permission
“–“ is used to remove the permission
“=” is used to assign the permission
3. chown: – to change owner of file or directory.
chown <new owner name> <filename with full path>

4. chgrp: – to change the group owner of file or directory.


chgrp <new group owner name> <filename with full path>

* IMPORTANT NOTE

1. IF YOU WANT TO GIVE THE PERMISSION WRITE ON FILE, THAT FILES


PARENT DIRECTORY SHOULD ALSO HAVE THE WRITE PERMISSION.
2. EACH USERS HOME DIRECTORY HAS PERMISSION 0700.(EXCEPT
root)
4. IF YOU WANT TO DO SOME WORK ON ANY DIRECTORY YOU
SHOULD HAV MINIMUM READ & EXECUTE PERMISSION.
5. BYDEFAULT WHENER YOU CREATE A FILE OR DIRECTORY ITS
GROUPOWNER IS PRIMARY GROUP OF THAT OWNER.

FOR PRACTICE: –
1. groupadd group
2. useradd –G group user1
3. useradd –G group user2
4. useradd user3
5. passwd user1
6. passwd user2
7. passwd user3
8. login with user’s user1,user2 & user3 on different console
(F1=root, F2=user1, F3=user2, F4=user3)
9. On F1,
mkdir /share
chmod 0777 /share
10. On F2
mkdir /share/user1
ls –l /share
chgrp group /share/user1
ls –l /share
cat > /share/user1/file
ls –l /share/user1/file
chgrp group /share/user1/file
ls –l /share/user1/
11. On F3
cat /share/user1/file (READ)
cat >> /share/user1/file (WRITE)
12 On F4
cat /share/user1/file (READ)
cat >> /share/user1/file (Permission Denied)
12. On F2
chmod 0646 /share/user1/file
ls –l /share/user1/
13. On F3
cat /share/user1/test (READ)
cat >> /share/user1/file (Permission Denied)
14. On F4
cat /share/user1/file (READ)
cat >> /share/user1/file (WRITE)

LINUX FILESYSTEM IN–DEPTH

Partitions & File systems


Disk drives are divided into partitions
Partitions are formatted with filesystems, allowing users to store there data
Default filesystem ext3 (Third Extended Linux Filesystem)
Other
ext2
iso9660 (CD)
msdos

INODES: –
ext2 & ext3 file systems keep a list of the files they contain in a table called
an inode table. An in individual entry in inode table is inode.
An inode table contains a list of all files in an ext2 & ext3 filesystems
An inode table contains information about file (the metadata): –
- file type, permissions, UID & GID
- link count (count of path names pointing to this file)
- the file size with modification date & time
- pointers to the files data blocks on disk
- other data about the file

DIRECTORIES: –
We commonly think of a directory as a container for files & other
directories, in fact directories is a mapping between the file names that humans use to reference
files and inode numbers

cp & inode
1. Allocates a free inode number, placing a new entry in a inode table
2. Copies data into a new file

EXAMPLE: –
1. cat > /root/file1
2. ls –il /root/file1
3. cp /root/file1 /
4. ls –il /file1

Inode no will different from the original file.


mv & inode
1. Creates a new entry with a new file name
2. Deletes the old entry with old fil name

EXAMPLE: –
1. cat > /root/file2
2. ls –il /root/file2
3. mv /root/file2 /
4. ls –il /file2
5. ls –il /root

Inode no will same, and original fill will not present.

rm & inode
1. Decrements the link count, thus freeing the inode number to be reused

EXAMPLE
1. cd /root
2. touch filea fileb filec
3. ls –il /root
4. rm –rf filea fileb filec
5. ls –il
6. touch file1 file2 file3
7. ls –il

Inode no of files file1, file2 & file3 will be same as the inode no of filea,
fileb & filec.

Hard link & inode


1. The rm command decrements the link count
2. When the link count is zero, the file is removed.

EXAMPLE: –
1. cat > /root/file
2. mkdir /root/dir
3. ln /root/file /root/dir/file
4. ls –il /root
5. ls –il /root/dir

Inode no will same for both files, because they are hard linked to each
other.

USING REMOVABLE STORAGE IN LINUX: –


1. To access a cd in RHEL4,
mount /media/cdrom
2. To access a cd in RHEL5,
mount /dev/cdrom /mnt
3. To access a USB devices in RHEL4,
mount /media/USB
4. To access a USB devices in RHEL5,
mount /dev/USB /mnt
5. To access a Floppy,
mount /dev/fd0 /opt
6. To disconnect any device,
umount /opt

Archiving files: –
Archiving files is the process of incorporating a copy of those files into a
single archive file. These makes easier to back up, store & transfer.

The tar command is used to archive.

tar <options> <filename to create> <filenames to archive>


–c create
–f forcefully
–v verbose
–x extract
Example: –
1. touch file1 file2 file3 file4
2. tar –cvf backup.tar file1 file2 file3 file4
3. ls
4. rm –rf file1 file2 file3 file4
5. ls
6. tar –xvf backup.tar
7. ls

Compressing file: –
Compression is used to make the file size less, and used save the
hard–disk size.

The gzip & bzip2 commands are used to compress.

gzip <filename to compress>


bzip2 <option> <filename to compress>
–k to keep original file unchanged
Example: –
1. touch file (Add some large data)
2. ls –l
3. gzip file
4. ls –l
5. gunzip file.gz
6. bzip2 file
7. ls –l
8. bunzip2 file.bz2
9. ls –l
10. bzip2 – k file
11. ls –l
my – name
Configuring the bash shell: –
To configure bash shell we have some variables through which we can
configure our shell. There are two types of variables: –
Local & environmental.

Some common variables: –


To configure the variables we have the command: –PS1=” []”
PS1=””
\h hostname
\u username
\d date
\t time
\w working directory
\! No of history commands

Example
To look your bash shell like follows;
[root@server~] you should give command;
PS1=”[\u@\h\w]”

Aliases
Aliases let you create shortcuts to commands.
alias command is used to see the set aliases.
alias c=clear
After this command you does not require to type whole command to clear
the screen just say “c”.

To make the aliases permanent we have to make the entry of aliases into
file .bashrc which is present in user’s home directory.

Shell startup scripts: –

/etc/profile
/etc/profile.d/
~/.bash_profile
~/.bashrc

CONFIGURING THE GNOME PANEL: –


Log on to GUI mode & check the available settings for your panel.
ADVANCE USES OF VI EDITOR

1. Multiple documents can be viewed in a single vim screen.


Ctrl+w, s splits the screen horizontally
Ctrl+w, v splits the screen vertically
Ctrl+w, arrow moves between windows
Ctrl+w, + to increase the size
Ctrl+w, – to decrease the size

:e to change the file being edited in window


:qa to quit all windows without saving
:set number to see the line numbers
:set all to see available other options
:set nonu to unset the line numbers
:help help topic

To learn more about vim just go through command vimtutor.

INTRODUCTION TO STRING PROCESSING


1 head –n <x=no of lines to see> <filename>
To see first ‘x’ no lines of file.

2. tail –n <x=no of lines to see> <filename>


To see last ‘x’ no of lines of file.

3. wc to count no of lines, words & letter


If we want to see individually we have options,
–l for no of lines
–w for no of words
–c for no of letters or characters

4. sort <options> <filename> to sort in order.


–r reverse
–n numeric
–f ignores case
5. uniq reports & omits the duplicate line

6. cut remove section from each line of files

Example

1.cut –f7 –d: /etc/passwd


2. cut –f7 –d: /etc/passwd | uniq
3. cut –f7 –d: /etc/passwd | uniq | sort
4. cut –f7 –d: /etc/passwd | uniq | sort –r
7. aspell –c <filename> to check the spelling mistakes in a particular
file
8.grep <options> print lines matching a pattern
–n shows no of line
–v not containing pattern
9. locate <filename> to search a file with filename

10.find <location> <string> <matching pattern>


–name
–size
–user

8. To find files in GUI mode, you will get tab in start/system/Search for
files

INVESTING & MANAGING PROCESSES

1.ps <options> report a snapshot of the current processes


–a all process status
–u process status with username
–x processes from all terminals
In the output you will get the information like,
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

2. kill –9 <PID> to kill the particular process

3. pstree to see the process tree of all processes

4.top displays Linux tasks

6. Scheduling the task


To schedule a particular task for the user, we have make the entry
of that task in file which is open’s after the command crontab –e. The
entry in crontab is not removed after the execution of command that entry
has to be removed by the user itself.
1. crontab –e : to edit the scheduler task file
2. Entry should be
* * * * * <command>
Min Hours DOM Month DOW
(0–59) (0–24) (0–30) (0–11) (0–6)

crontab –l to see the scheduled task for that user

crontab –e

25 13 15 03 02 touch file1 file2


26 13 15 03 02 tar –cvf backup.tar file1 file2
27 13 15 03 02 rm –rf file1 file2

Вам также может понравиться