UNIX
1969 Ken Thompson from AT&TS Bell Telephone Labs wrote first version of UNIX
Operating System.
1973 Development of UNIX was rewriting of the kernel in C, by Ritchie & Thompson.
1975 First distribution of UNIX software was made by Berkeley groupknownas BSD.
1978 Seventh edition of operating system was released with support of many different
hardware architectures.
PRINCIPLES OF UNIX
FREEDOM TO IMPROVE
MULTI-USER, MULTI-TASKING
NOTHING IS AUTO-EXCUTABLE
SYSTEM SECURITY.
More
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 computers 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
It acts as the command interpreter between the user & hardware (Kernel).
It expands the various meta characters used in file operations
It is responsible for the redirection output of one command as the input for the other.
It is responsible for executing the shell scripts which uses the programming language.
(Commands)
It is responsible to setting the environment for the user.
2
More
TYPES OF SHELL
sh
-
Bourne shell
csh
-
C shell
ksh
-
Korn Shell
tcsh
-
bash
-
Features
Command completion
Command line editing
Use of various meta characters
History
More
LINUX
FEATURES OF LINUX
More
Red Hat Enterprise Linux 6 is the next generation of Red Hat's comprehensive suite of operating
systems, designed for mission-critical enterprise computing and certified by top enterprise
software and hardware vendors.
This release is available as a single kit on the following architectures:
o I386
o AMD64/Intel64
o System z
o IBM Power (64-bit)
In this release, Red Hat brings together improvements across the server, systems and the overall
Red Hat open source experience.
Local logins:
Graphical login
Virtual Consoles
Multiple Non-GUI logins are possible through the use of Virtual Consoles
More
Xfree86
GNOME
KDE
X Window System
GNOME
KDE
K Desktop Environment
More
<options>
<directory>
-l
long listing
-a
-h
-i
<enter>
recursively
-f
forcefully
More
11. who to see the information about the users logon to local machine
Syntax: who
16. touch to modify date & time of file (creates empty file)
Syntax: touch
More
22. logout
Syntax: logout
23. poweroff
Syntax: poweroff
24. reboot
Syntax: reboot
HELP COMMANDS
1. man <command>
2. info <command>
3. <command> --help
4. whatis <command>
More
10
More
/boot
/bin
/dev
/etc
: - Configuration files
/home
/lib
: - Library files
/media
: - By default mount point for the removable storage when you mount
from GUI mode
/misc
: - Miscellaneous files
/root
/sbin
/tmp
: -Variable files
More
As you all know in Red Hat we do our maximum work 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,
-rw-r--r--
1 root root
In the above case you will some different characters at the starting, from where you will the
kind of file.
12
More
: keyboard is default
>
file
>> Command
>
file
< Command
<
file
2> Command
2>
file
2>>
file
to file
2>>
Command
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.
Pipes (|) let you redirect output from one command to become input to another command.
Syntax
<Command1>
| < Command2>
Any command that writes to standard output can be used on left-hand side of a pipe.
Any command thats read from standard input can be used on the right-hand side.
Multiple commands can be chained together with pipes.
13
More
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,
vim <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.
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
More
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.
Undoing changes
u
<ctrl-r>
EX MODE: -
:w
:q
:wq
:w!
:wq!
15
More
Ctrl+w, s
Ctrl+w, v
Ctrl+w, arrow
Ctrl+w, +
Ctrl+w, -
:e
:qa
:set number
:set all
:set nonu to
:help
help topic
16
More
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
(UID 1 to 499)
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
17
useradd
<options>
-d
home directory
-c
comment
-s
shell
-g
-G
secondary group
-u
uid
<username>
More
usermod
<options>
-d
home directory
-c
comment
-s
shell
-g
-G
secondary group
-u
uid
-l
login name
<exist username>
passwd <username>
Syntax:
passwd
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.
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.
userdel: -to delete a particular user.
18
Syntax:
userdel
Syntax:
userdel
<username>
-r
<username>
More
groupmod
<options>
-g gid
-n to change the group name
groupdel: -to delete the group.
Syntax:
groupdel
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.
19
More
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,
Read only
Write
Execute
You can see the permissions of files 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
umask is the command with you can see the user mask of particular user & also you can set
the user mask.
20
More
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 root root
In this example you are getting 10 permissions which you have to divide in 4 categories
which will be like follows
d
rwx
special
owner
r-x
group
r-x
other
EX. chmod
21
0777 /home/user1/test/
More
2. 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
22
More
* IMPORTANT NOTE
1. EACH USERS HOME DIRECTORY HAS PERMISSION 0700.(EXCEPT root)
2. IF YOU WANT TO DO SOME WORK ON ANY DIRECTORY YOU
SHOULD HAV MINIMUM READ & EXECUTE PERMISSION.
3. BYDEFAULT WHENER YOU CREATE A FILE OR DIRECTORY ITS
GROUPOWNER IS PRIMARY GROUP OF THAT OWNER.
FOR PRACTICE: -
groupadd group
useradd user3
passwd user1
passwd user2
passwd user3
mkdir /share
On F2
23
mkdir /share/user1
ls l /share
ls l /share
cat
> /share/user1/file
More
ls -l /share/user1/file
chgrp
ls l /share/user1/
group /share/user1/file
On F3
-
cat /share/user1/file
cat >>
/share/user1/file
(READ)
(WRITE)
On F4
-
cat /share/user1/file
(READ)
cat >>
(Permission Denied)
/share/user1/file
On F2
-
chmod 0646
ls l /share/user1/
/share/user1/file
On F3
-
cat /share/user1/test
cat >>
/share/user1/file
(READ)
(Permission Denied)
On F4
24
cat /share/user1/file
cat >>
/share/user1/file
(READ)
(WRITE)
More
INODES: -
ext2 & ext3 file systems keep a list of the files they contain in a table called an inode
table.
An inode table contains a list of all files in an ext2 & ext3 filesystems
More
cp & inode
Allocates a free inode number, placing a new entry in a inode table
Copies data into a new file
EXAMPLE: -
ls il /root/file1
cp /root/file1 /
ls il /file1
ls il /root/file2
mv /root/file2 /
ls il /file2
ls il /root
rm & inode
26
More
Decrements the link count, thus freeing the inode number to be reused
EXAMPLE
-
cd /root
ls il /root
ls il
ls il
Inode no of files file1, file2 & file3 will be same as the inode no of filea, fileb & filec.
ln <filename> <linkname>
EXAMPLE: -
mkdir /root/dir
ln /root/file /root/dir/file
ls il /root
ls il /root/dir
Inode no will same for both files, because they are hard linked to each other.
Soft link & inode
27
More
ln s
<filenmae>
<linkname>
EXAMPLE: -
mkdir /root/dir1
ln s /root/file1 /root/dir1/file1
ls il /root
ls il /root/dir1
df
<options>
human readable
<filesystem>
Floopy
mount /dev/fd0
/mnt
CD
mount /dev/cdrom
/opt
USB
fdisk
-l
mount /dev/sda1
/opt
Formatting a Floppy
mkfs.vfat
28
/dev/fd0
More
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.
Synatx:
tar <options>
<filename to create>
-c
create
-f
filename
-v
verbose
-x
extract
<filenames to archive>
Example: -
29
cd /root
vi a
vi b
vi c
tar cvf
ls
rm rf a b
ls
a b c
More
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.
Syntax:
gzip
<filename to compress>
Syntax:
bzip2
<option>
-k
<filename to compress>
Example: -
30
cd /root
vi test
ls l
gzip test
ls l
gunzip test.gz
bzip2
ls l
bunzip2
ls l
bzip2
ls l
test
test.bz2
-k
test
More
head
<filename>
2. tail
<filename>
3. wc
for no of lines
-w
for no of words
-c
4. sort
<options>
<filename>
-r
reverse
-n
numeric
-f
ignores case
to sort in order.
5. uniq
6. cut
Example
31
1. cut f7 -d:
/etc/passwd
/etc/passwd | uniq
More
<options>
-n shows no of line
-v not containing pattern
9. locate <filename>
10. find
To find files in GUI mode, you will get tab in start/system/Search for
32
files
More
1. ps
<options>
-a
-u
-x
R Runnable
S Sleeping
T Stopped
D Uninterruptable
2. kill -9 <PID>
3. pstree
4.top
5. jobs
6. fg
More
1. at:
at <time>
<command> ctrl+z
atq
atrm <jobId>
2. cron To schedule a particular task for the user, we have make the entry of that task in
file which is opens 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.
crontab e
Min
(0-59)
hours
<command>
34
More
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
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: -
Some common LOCAL variables: 1. HISTFILESIZE: Determines how many commands to be saved in the history file on
logout.
2. COLUMNS: Sets the width of the terminal
3. LINES: Sets the height of the terminal
4. PS1: Sets the prompt
To configure the prompt we have the command: -PS1= []
PS1=
\h hostname
\u username
\d date
35
More
\t time
\w working directory
\! No of history commands
Example
To look your bash shell like follows;
[root@server~]
PS1=[\u@\h\w]
To make changes permanent save the upper line in file ~/.bash_profile
36
More
Login Shells
/etc/profile
/etc/profile.d
~/.bash_profile
~/.bashrc
/etc/bashrc
Non-login Shells
~/.bashrc
/etc/bashrc
/etc/profile.d
/etc/profile
-
/etc/profile.d
-
37
Aliases
More