You are on page 1of 16

RED HAT Essentials

Ch.1
History
1984 GNU project began by Richard Stallman, write replacement tools
for Unix like (chmod, ls)
They put these S/W under GPL which have 4 freedom (write to use,
modify, redistribute, distribute modifications.
1991 linus trovalds (Finland) develop Linux kernel "ver. 0.02 now
2.6 "
Complete open source + unix like O.S = Linux kernel + GNU unities
Red hat distributions
RHEL
FEDORA
There are now around 200 Linux distributions.
To obtain kernel www.kernel.org
Kernel naming X.Y.Z
X major no.
Y minor no. If even it is stable else it is a
development kernel
Z release

CH.2

Basics
Two types of login virtual console (text)
GUI login "display manager" gdm
start GNONE desktop
To switch between V.C's & GUI environment alt + ctrl + F1 F7.
Desktop environment is a collection of configurations and tools that
define how a graphical environment should like .
X server (desktop) will start on ctrl + alt + F7.
To change your password system preferences about me OR
#passwd
To login by another identity #su username
Text editor nano , gedit , emacs, vi

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 1


Ch.3
Help & commands
Command syntax #command option arguments
- a (or -abc)
-- help
+x
Example: #date +%"now is % A, %B, %d, %y, %n it is %r"
#cal 9 2010
Help

#whatis cal to generate DB #makewhatis

#date -- help

#man [<chapter>] command


1 command (default)
5 file format
2 system calls
6 games
4 special files

8
/text search on man /n/N /q (next / previous / quit)

#man k keyword use whatis DB

#Info in depth like web site "* is a link"


Tab move to next link
Enter follow the link
N / p / u next /previous /up
s search
q quit

# /usr/share/doc samples of configuration files


PDF, html

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 2


Ch.4
F.S Browsing

Root directory or slash (/) contain the following Directories:

/root, home (home directories for root and users)


non essential
/bin (Essential), /usr/bin, /usr/local/bin (user executable files)
S/W compiled from source

non essential
/sbin (Essential), /usr/sbin, /usr/local/sbin (system exec. Files)
S/W compiled from source
/mnt, /media (removable) (mount points )
/etc (Configuration files)
/tmp (delete after 10 dyes)
/boot (Kernel and boot files)
Log, mail, spool
/var, /srv (DB, apache) (server data )
/proc, /sys (H/W) (system info.)
/lib, /usr/lib, /usr/local/lib shared lib.

#pwd print current directory


* The paths may be absolute path or relative paths
#cd
#cd tilde
#cd ..
#cd - previous. dir
#ls a
#ls l
#ls R
#ls ld
#cp r recursive dir (copy or rename)
i interactive (ask before overwrite )
#mv
#rmdir
#touch
#rm r directory
f force for write protected files
i interactive
Nautilus "GNONE"

Drag & drop to copy OR context menu

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 3


#file filename compare the contents with pattern in /usr/share/magic to
determine file type.

Ch.5
User & Group & permissions
Uid of root is 0
Users have uid, gid, home directory ,login shell in /etc/passwd,
/etc/group
Private group has the same user name
Permission precedence uid, gid, other
#chmod Permission file/dir.
4 r read list "ls"
2 w write create /remove
1 x exit cd & ls - l
#chown [ - R] mm file
#chgrp [ - R] frinds file
#chmod [ - R ] augo rwx file
a all
u owner
g group
o other
= assign
+ add
- remove
#chmod 644 file

Ch.6
Using bash shell
Wild card expansion
* replace zero or more character
? replace one character
[0 9] replace one digit from 0 to 9
[abc] replace one char. (a or b or c)
[^ abc] not
[: keyword:] keyword alpha, upper, lower, digit, alnum,
Space
Ex. [[: digit]] or [^ [: alpha:]]
Tab completion "commands & file names"
#history

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 4


!! repeat last command
! char repeat last command that start with chan
! num
!n repeat last command entered n command back
!? abc repeat last command that contain abc
Alt +. Recall last argument
refere to home hir
Ahmed/mm
Command expansion $( ) or `command`
Brace expansion {}
#touch file{1, 2, 3}
Ctrl + a move to line start
e move to end
u delete to line start
k delete to end
In Gnome
Ctrl + shift create new tab
Ctrl + pgup/pgdown switch to tab
Ctrl + shift + c copy selected text
Ctrl + shift + v paste
Scripts text file contain a series of commands
for automate commands & text processing
Sequence #! /bin/bash
# Comment
#chmod u+x script $ /home/usr/script
OR $./script
OR in PATH variable

Ch.7
Redirection & pipes & for
standard i/p file describtor 0 , <
o/p file describtor 1, >, >>
&> o/p & error
Error file describtor 2, 2>, 2>>
find /etc - name passwd > find.out 2> find.err
pipe "|"
#echo "test print" | lpr
#echo "test mail" | mail s "test" root
#find /etc name passwd &> find all redirect all
# (cal 2007, cal 2008) | less combine out of multiple commands
tee

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 5


#ls l /etc | tee file | sort
#ls l /etc | tee file on the screen

#tr "A Z " "a z" < test file i/p redirection

#cat test file | tr "A Z" "a z"
#cat < file # cat file
#cat > file output redirection
$mail s " test" root@example.com << END
> Hi
> man
> END sendins multiple lines to STDIN
$
for name in ali mm nn
do
echo welcome | mail s testmail $name
done
for n in ` cat file `
do
echo "$n"
done
for n in {1..20}
do
ip=10.0.0.$n
ping c2 $ip &> /dev/null
if {$? = 0}, then
echo" $ip is up"
else
echo "$ ip is down"
fi
done

Ch.8
Text processing tools
#cat file1 file2 file3 "concatenate"
If #cat "binary file" terminal will unusable so use #reset
#cat b
Number each line

#less /ali search like man

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 6


n next
N prev.
g tap
G end

#head n /etc/passwd
#tail n /etc/passwd
f
#grep mm /etc/passwd
-i case insensitive ,
- n print line numbers of match,
- v not contain , - c count
-r recursive , - l only files names
-AX print line after match
-BX print line before match

#cat d: - f1 /file
#cat d" c2 5 /file
#ifconfig 1 grep 'inet addr' 1 cat d: - F2 1 cat d " " F1
#wc l
w
c
m char. cont "not displayed"
#sort r reverse
n numeric
u uniq
t: use ":" as a filed separator
k x sort by ":" delimited filed x
#sort t: - k 3 n /etc/passwd uid field
#sort t: - k 3.2 n /etc/passwd

Filed . char. within the field to begin the sorting


#uniq u lines that are unique
d print one copy of the lines that are re peated
c print the unmbers of repetition
i/p to uniq must be sorted
Without option remove duplicate lines
- fn , sn avoid compare the first n field or char
#sort u uniq
#aspell check file list the error word and its correct
#aspell list < file list the error word

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 7


#look exer list the complete word that start with exer
#tr 'A Z ' 'a z ' < file
#sed 's/cat/dog/' file one change in a line
#sed 's/cat/dog/gi' file global & case insensitive
multiple change per line
#sed '1,50s/cat/dog/g' file
#sed e 's/cat/dog/g' e 's/cow/bird/g' file multiple edit
#sed f mm filename mm file has the required changes
in the previous format
Special char. for complex search [ in grep, sed, less]
^ Line begins
$ Line ends
Like [xy] x or y
bash [^ x y] not x or y
[[:upper:]]

Ch.9
Vim
Adv. : speed , most unix types
Disadv. : difficult
Modes command
Insert
Ex mode
Esc exit current mode & esc esc exit to
command mode
Insert mode A append end of line , a after the cursor
I append begin of line it before the
curser
O inserts new line
Ex. :w
: wq
: q!
Command mode
w move word
b move word
G jumb to end
2G jumb to line 2
() move by sentence
{} move by paragraph

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 8


Search as less (/dog search down word) & (?dog search up
word )
Search and replace as sed but in the current line
all lines :%s/dog/cat/g replace in all file
: s/dog/cat replace once in the same line
:1,5s/cat/dog/g

In command mode change cut copy paste


cc copy line dd yy p
c} paragraph below d} y} p
c{ paragraph above d{ y{ p
c)
c(
u undo last change
U undo last changes on the line
Ctrl + r redo
: set number (:set un or :set noun)
: set ignorecase (:set ic or : set noic)

#vim o file1 file2 start multiple window "windowing mode" or "vim


only"
Ctrl + w, s split screen hors,
Ctrl + w, v split screen vertical
Ctrl + w, arrow move between window
Ctrl + w, n create new window
Ctrl + w, t resize deceive window

Ch.10
#ifconfig eth0
#ifup eth0
#ifdown eth0
#systemconfignetwork deactivate activate
#nano /etc/sysconfig/networkscripts/ifcfgeth0
#service network restart
#dhclient
#nano /etc/sysconfig/network
#route add default gw 10.0.0.1
#ifconfig eth0 10.0.0.2
#nano /etc/resolv.conf

Print requests (jobs) sent to queue which sent to printers

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 9


# systemconfigprinters OR http:// local host: 631
To definu local printer queue type locally connected /dev/ lp0
if usb rescan devices
Generic print device used for most unsupported printers
Configuration stored in /etc/cups/printers.conf
#lpr file ( lp)
#lpq view queue content ( lpstat)
#lprm job no. ( cancel)
#evince PDF viewer
#lpstat p list configured printers
#ps2pdf
#pdf2ps
#pdftotext
#enscript & a2ps convert text to post script
#systemconfigdate
#date [mmddhhmm [[cc]yy][.ss]

Ch.11
Processes
PID
UID & GID & SE Linux context determine F.S access which
inherit from the executing user
#ps a x u f
(a) all terminals
(x) process not attached to terminal
(u) display process owner
(f) print process parent

e all
elfy more info.
o pid, comm., %cpu, %mem, state, tty

Process status
Running use CPU now .
Sleeping in memory but not doing any thing.
"Error uninterruptible sleep" waiting for resource to because available
[wait for an event] (ex. I/O over fail net
NFS connection.
Zombie terminated but not flushed from process
list.

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 11


* before process die it sends signal to its parent & wait for ack. If parent
does not ack. all resources except PID are released
#pgrep cups
#pidof cups match the name
#ps axo pid, comm | grep 'cups'
Signal interprocess communication
15 TERM terminate cleanly
9 KILL terminate immediately may cause
Zombie
1 HUP re read configuration file
INT (ctrl + c) TERM
# Man 7 signal
Sending signals to process
Pid #kill 9 pid
KILL
Name #killall TERM cupsd
Pattern # pkill 9 cups
Nice value determine process priority [ 20 19]

High priority low priority
$ nice n 5 comm.
$ renice 5 PID
$ renice 15 PPID root only
Process monitor
# top
# Gnome system monitor
Job control
#firefox &
#ctrl + Z or single 17 (stop)
#bg %job no.
#fg % job no.
#jobs
#kill 9 %job no.
o/p of interactive job in background appear on screen

Create #at time #crontab e


List #at l #crontab l
Detail #at c job no. --------
Remove #at d job no. #crontab r
#at 7 am Thursday #crontab u username
now + 5 minutes min hour DOM month DOM
8 : 00 pm December 7 * 1, 2, 3

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 11


conditional execution
&& AND then
| | OR else
#ping c 10.0.0.1 &> /dev/null && echo "life" || echo "died"
test command
$ test "$A" = "$B" ["$A" = "$B"] string
$ test "$A" eq "$B" integers
[ - f /test] && source test script
-d dir
-f file "regular"
-x executable
-r readable
-e file
if ping c 2 10.0.0.1 &> /dev/null ; then
echo "up"
elif ping ; then
else
echo
fi
# for x in { 9100000..9110000}
do
grep $x in ~/file.txt > /dev/null | | echo $x > result

Ch.12
Configure bash shell
Variables
#m="hellow"
Variable 1) local var. "shell var."
2) Environment var.
(1) Local var. user to configure the shell itself
(2) Shell will pass env. var. to the program that call it used to
configure other commands
#set display all var.
#env display env. var.
#echo $HOME display single var.
Ex: - env. var
PSI ="\a, \h" prompt
\a username
\w current working dir.
\h hostname

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 12


\! history no. of the current command
\$ show $ if user & #if root
Example on environment var. PATH, EDITOR, HISTFILESIZE, HOME,
EUID
#alias dir = 'ls la'
#unalias
To prevent expansion
#echo \$5 $5
' ' inhibit all expansion
" " inhibit all expansion except $, ` , \, !

Login shell su - /etc/profile call /etc/profile.d


"Global"
Created shell at login ~/.bash_profile call ~/bashrc call
/etc/bashrc
Non login shell SU
Graphical terminal ~/bashrc /etc/bashrc
Executed script /etc/profile.d
Any other bash

Bash exit tasks when exist login shell


~/bash_logout
Take I/p with positional parameters
$1, $2 $9, ${10}, ${11}, $*, $#, $0

All argument
No. of arg.
Command name
Read
# read p "Enter name" name
Which command find the path for the executable file (command)

Ch.13
Find
#locate name (updatedb daily executed from /etc/updatedb.conf)
- i case insensitive
- n x list only the first x matches
#find [dir.] [criteria] [action]
Only search dir. where the user has read & execute permission
#find / perm 022 exec chmod o w { } \;
ok
User

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 13


group
name
(Case insensitive) iname
user mm group xx AND
user mm o group xx OR
not \( user mm o group xx\) not
# find size 1024 1 Mbyte
+ 1024
-1024
mmin min | mtime day last change to file data
cmin min | ctime day last change to file metadata
amin min | - atime day last access to file data
# find size 1024 exec { } \;
ok { } \;
# find /tmp ctime + 3 exec chmod o w { } \;
# find / - name mm - ok cp { } { }.old \;
Gnome search tool

Ch.14
Web client
Firefox features fast, popup blocking, tabbed browsing
# links http:// www.redhat.com show the site
# Links dump http:// www.redhat.com show then exit
# links source http:// www.redhat.com show source
# wget http:// www.redhat.com/index.html
# wget recursive -- level = 1 http:// www.site.com
Evolution email client "in fedora"
Thunderbird email client "mozilla email client"
Kmail KDE email client
Mutt non Gui email client [#mutt f imaps://user@server]
Gaim or kopete IM tools support msn, yahoo, icq, irc.
RH client RH server
#ssh root@IP ['command'] allow authenticated, encrypted access to
remote system
# scp source destination
user@host:/path
r recursive
#sftp
#rsync fuster than scp it capies difference
a recursive
-- Progress print progress bar

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 14


# rsync *.conf 10.0.0.1:/home/config
Open ssh key based authen tication
# sshkeygen t dsa /.ssh/id_dsa
# sshcopyid i .ssh/id_dsa.pub
#lftp u mm ftp.example.com
#gftp
# smbclient L 10.0.0.1 share list
#smbclient u mm //10.0.0.1/home access /home share dir.
File transfer with nautilus
smb:// list all SMB server
smb://example.com list example.com SMB
ftp://ftp.mm.com
X org clients
# ping
# truceroute
# host
# dig
# netstat
# gnomenettool GUI

Ch.15
Advanced users & permissions
/etc/passwd UID, gid
/etc/group
/etc/shadow
# systemconfigusers
# useradd
# usermod
# userdel
#w show connected users
# last show recent login
# lastb show last bad login
Special permission for executable suid run with owner
perm.
sgid run with group
owner perm.
Special permission for directions sticky
sgid
1 sticky
2 sgid
4 suid

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 15


# Chmod 3777 die
sgid + sticky

Ch.16
Linux file system
Inode table contain inode entries which contain file type , UID, GID,
size, time stamps, pointers to the file's data blocks on disk, permission,
link count
Directory is a map between human name & inode number
# ls il
Hard links
Adds an additional pathname to reference a single file per file system
# ln filename [link name]
Soft links "symbolic"
A file that points to another file "its symbol is l"
# ln s filename link name
# df h disk partitions usage
# du hs directory & files usage in kilobyte
# mount
# zip & # unzip
# gzip & # gunzip
#bzip2 & # bunzip2
# tar c create
t list
x extract
v verbose
f archive name
z compress

Ch.17
System admin tools
Installation
# service
# chkconfig
# Systemconfigservices
# rpm
# yum
# priut adds /removes S/W
Selinux
Firewall # system-configsecuritylevel

Dr. Eng. Mostafa Elgamala- 83883334440 - Dr.mostafa.elgamala@gmail.com 16

You might also like