Vous êtes sur la page 1sur 28

RED HAT LINUX

PART 1
RED HAT LINUX:
Basic Administration

Anil Vajragiri Page 1


RED HAT LINUX

CHAPTER 1
INTRODUCTION
1. The Operating System
Operating system is software that manages software and hardware resources
and provides common service. It acts as an interface between programs and
hardware resources that these programs access (like memory, hard disk and
printer). It is loaded into memory when a computer is booted and remains
active as long as the machine is up. OS performs below actions:
a. Allocates memory for programs
b. Loads CPU registers with control information related to the program
c. Keeps track of programs that are executed, helps to resume a program
d. Communicates with Hardware
e. Cleans up memory once program execution is completed

OS types:
a. Single user – MS-DOS – Single user Single task
b. Multiuser – UNIX, Linux, Windows – Multiuser Multitasking.

Early computers were designed to perform series of single tasks like


calculations. Basic OS features were developed in early 1950s such as
‘Resident monitor’ to perform series of automated functions, but fewer
complexes. Modern OS features start developing when PC gained the
popularity and OS became complex. Libraries were linked to the user
programs to assist the operations such as I/O, which is like modern OS. ‘Atlas’
is treated as first modern OS.

2. UNIX
UNIX owes its origin at Bell labs by AT&T, Massachusetts Institute of
Technology and GE. 1965 –AT &T, Bell labs and GE Dennis Ritchie, Ken
Thompson, Brain Kernighan, Douglas Mcllroy, started the developing OS in
‘Assembly language’ with multiuser and multitasking features named
MULTICS. Bell labs withdraw from the project due to size and complexity of
the project. But Dennis Ritchie and Ken Thompson decided to complete the
project in smaller scale.
Peter Neumann in 1970 named the project as UNIX (UNiplex Computing
Information Systems).
1971 first version of Unix was released.
In 1972 Ken Thompson rewrote the Unix in ‘C’ language. AT&T licensed Unix
to outside parties from late 1970s, leading to a variety of both academic and
commercial variants.

Variants:
AT & T System V
BSD University of California.
AIX IBM
HP-UX Hewlett-Packard
Xenix Microsoft
Solaris SUN Microsystems
OS X Apple Inc.

Anil Vajragiri Page 2


RED HAT LINUX

AT&T sold its rights to Novell – 1990s


Novell sold the right to SCO – 1995

UNIX Philosophy:
a. Portability
b. Multi-tasking
c. Multi-user
d. Time-sharing
e. Plain-text to store data
f. Hierarchical file system
g. Inter-process communication
h. Software tools
i. Command-line interpreter

UNIX is together with KERNEL a ‘master control program’ and utilities.


User communicates with Unix system through command interpreter called
Shell. The power in the Unix lies in combining different commands.
Contributions made by the academic community and industries have also led
to the enrichment and fragmentation of UNIX.
You can use any one of these shells if they are available on your system. And
you can switch between the different shells once you have found out if they
are available.

SHELL
1. Bourne shell (sh)
2. C shell (csh)
3. TC shell (tcsh)
4. Korn shell (ksh)
5. Bourne Again SHell (bash)

Bourne shell (sh)


This is the original Unix shell written by Steve Bourne of Bell Labs. It is
available on all UNIX systems. This shell does not have the interactive
facilities provided by modern shells such as the C shell and Korn shell. You
are advised to use another shell which has these features. The Bourne shell
does provide an easy to use language with which you can write shell scripts.

C shell (csh)
This shell was written at the University of California, Berkeley. It provides a
C-like language with which to write shell scripts - hence its name.

TC shell (tcsh)
This shell is available in the public domain. It provides all the features of the
C shell together with emacs style editing of the command line.

Korn shell (ksh)


This shell was written by David Korn of Bell labs. It is now provided as the
standard shell on Unix systems. It provides all the features of the C and TC
shells together with a shell programming language similar to that of the
original Bourne shell. It is the most efficient shell. Consider using this as your
standard interactive shell.

Anil Vajragiri Page 3


RED HAT LINUX

Bourne Again SHell (bash)


This is a public domain shell written by the Free Software Foundation under
their GNU initiative. Ultimately it is intended to be a full implementation of
the IEEE Posix Shell and Tools specification. This shell is widely used within
the academic community. bash provides all the interactive features of the C
shell (csh) and the Korn shell (ksh). Its programming language is compatible
with the Bourne shell (sh). If you use the Bourne shell (sh) for shell
programmings consider using bash as your complete shell environment.

Summary of shell facilities:


Bourne C TC Korn BASH
________________________________________________________
Command history No Yes Yes Yes Yes
Command alias No Yes Yes Yes Yes
Shell scripts Yes Yes Yes Yes Yes
Filename completion No Yes* Yes Yes* Yes
Command line editing No No Yes Yes* Yes
Job control No Yes Yes Yes Yes

POSIX
People all over the globe began to develop tools for UNIX. Unfortunately,
there was no coordination to guide all the development. This caused a lot of
differentiation between the different versions of UNIX. Finally, standards
started to appear. For UNIX, many of the standards fall under the IEEE
(Institute of Electrical and Electronics Engineers) POSIX (an acronym for
Portable Operating System Interface) standard.

3. LINUX
Linux is OpenSource software released on 5th October 1991. Linux is Unix-like
OS uses monolithic kernel. Linux is originally developed for x86 platform but
ported to more computer hardware platforms. There are different
distributions in Linux like Redhat, Debian, Ubuntu, Linux Mint, Fedora,
openSUSE etc.

At commercial level:
1. Redhat Enterprise Linux
2. SUSE Linux Enterprise Server.

Linux distribution includes


1. Linux Kernel
2. Utilities
3. Libraries

1991 Linus Torvalds, Finnish, student from University of Helsinki developed


his own Kernel using MINIX and developed the OS using GNU applications
replacing MINIX applications. MINIX operation system is developed by
Andrew S Tanenbaun in 1987 for educational purpose. Later the development
shifted to develop highly reliable and self healing micro-kernel. The main
difference between Linux and Minix is, Minix uses Micro-Kernal while Linux
used Monolithic kernel. Torvalds wanted to call his work as ‘FREAK – Free,

Anil Vajragiri Page 4


RED HAT LINUX

Freak, Unix. But his colleague Ari Lemmke uploaded the data to FTP server
with name LINUX.

 Fresh implementations of UNIX APIs


 OpenSource development model
 Supports wide variety of Hardware
 Supports many networking protocols
 Good Vendor support

GNU
GNU is recursive acronym for ‘GNU’s Not Unix’. GNU’s UNIX is Unix-like
and does not contain UNIX source code and uses free software. The goal to
bring completely free software OS. GNU started by Richard Stallman in 1983
at Massachusetts Institute of Technology (MIT).

Probably the best feature of Linux, the GNU utilities in general, and Red Hat
Linux in particular is that they are distributable under the terms of the GNU
Public License (GPL).

4. ARCHITECTURE OF UNIX
The architecture of Unix can be divided into three levels of functionality.
1. Kernel – lowest level – Schedules tasks, manages resources.
2. Shell – interface between user and kernel – interprets commands
3. Utilities – user support

Figure: UNIX Architecture


1. Hardware – x86
2. Kernel - Monolithic
3. Shell – Bash, Ksh, Tshell, Zshell
4. Utilities – cat, who, sed, grep, vi.

Anil Vajragiri Page 5


RED HAT LINUX

5. FILESYSTEM HIERARCHY

Filesystem architecture in Linux is inverted tree like. ‘/’ is the root filesystem
and is on top of all filesystems.

/ Top most directory and parent to all directories. It is called as


root directory/
/root This is home directory of the root user. It is the working
environment to the root user or super user.
/home This is the default home directory of all other users. It provides
working environment to the users.
/boot Contains bootable files vmlinux (Kernel) and Initrd (INITial
Ram Disk) and GRUB (Grand Unified Boot loader)
/etc It contains all configuration files.
/etc/passwd
/etc/shadow
/etc/rc.d
/etc/cron
/usr By default the software packages are installed in this directory
(UNIX Sharable Resources).
/opt It’s optional directory for /usr. Third party software are
installed here.
/bin All command binaries for the users are located here.
/sbin Holds all superuser command binaries
/dev Its directory for device files.
/dev/had
/dev/sda
/proc It contains process files. The contents of the directory is not
constant varies based the processes that are running. Virtual
Filesystem.
/proc/cpuinfo
/proc/meminfo
/var Location for the logs.
/mnt It is default mount point for any partition.
It is empty by default.
/media It contains the removable media like pendrive, CD-ROM.
/lib It contains library files which are used by the OS.
It is similar to the dll files in WINDOWS.
Library files in Linux are SO files (Shared Objects).

Anil Vajragiri Page 6


RED HAT LINUX

CHAPTER 2
INSTALLATION

What kind of system is needed to run Linux? The actual hardware


requirements for the system change periodically or the Intel versions, a
hardware configuration that looks like the following is required:
Any 80386, 80486, Pentium or Pentium II processor will do. Non-Intel clones
of the 80386 and up will generally work. You do not need a math coprocessor,
although it is nice to have one.
The ISA, EISA, VESA Local Bus and PCI bus architectures are supported. The
MCA bus architecture (found on IBM PS/2 machines) has been minimally
supported since the 2.1.x kernels, but may not be ready for prime time yet.
You need at least 4 megabytes of memory in your machine. Technically, Linux
will run with only 2 megs, but most installations and software require 4. The
more memory you have, the happier you'll be. I suggest an absolute minimum
of 16 megabytes if you're planning to use X-Windows; 64 is better.
Of course, you'll need a hard drive and an AT-standard drive controller. All
MFM, RLL, and IDE drives and controllers should work. Many SCSI drives
and adaptors are supported as well; the Linux SCSI-HOWTO contains more
information on SCSI. If you are assembling a system from scratch to run Linux,
the small additional cost of SCSI is well worth it for the extra performance and
reliability it brings.
You'll want a CD-ROM drive; effectively all Linux distributions are now CD-
ROM based.
You also need an MDA, Hercules, CGA, EGA, VGA, or Super VGA video card
and monitor. In general, if your video card and monitor work under MS-DOS
or Windows then they should work under Linux. However, if you wish to run
the X window system, there are other restrictions on the supported video
hardware.

Minimum HW requirement for RHEL 6

1. Processor AMD/INTEL DUAL CORE


2. Mother Board Normal/VT Enabled
3. RAM 1 to 2 Gb
4. Hard Disk 20 – 40 Gb

Minimum Partitions and Sizes Required

1. / (root) 15 to 20 Gb
2. /boot 200 Mb
3. SWAP twice the RAM

Anil Vajragiri Page 7


RED HAT LINUX

RHEL 6 Installation

a. Enter into BIOS settings and make CD/DVD as first boot device.
b. Make sure that VT (Virtual Technology) enabled for RHEL6 64 bit.
c. Boot the system with RHEL6 CD/DVD.
d. Follow the below screens to complete installation.

Anil Vajragiri Page 8


RED HAT LINUX

CHAPTER 3
BASIC ADMINISTRATION
# cat:
Used to create the file.
Modify the contents of file.
Redirect the contents of a file with redirection options
Use Ctrl+D to save the contents and Ctrl+C without saving the data.

$ cat > test - Creating a file name ‘test’


This is test file created
Shradda technologies
Ctrl+D

$ cat >> test – appending a existing file


This line is newly added to the existing file ‘test’
without erasing existing data
Ctrl+D

$ cat –n test --- gives numbers to the records


$ cat –e test --- gives $ prompt at the end of the line
$ cat –s test --- squeezes the spaces in the file
$cat –t test --- indicates the tabs
$ cat –b test --- Numbers are given to only the records
$ cat > .hidden_test --- to create a hidden file
$ cat .hidden_test --- to see the hidden file contents

#touch
Creates an empty file
$ touch test_empty.txt --- creates an empty file
$ touch test1 test2 test3 --- creates multiple empty files.

# mkdir
Create the DIRECTORY(ies), if they do not already exist.
-m, --mode=MODE
set file mode (as in chmod), not a=rwx - umask
-p, --parents
no error if existing, make parent directories as needed
-v, --verbose
$ mkdir test_dir --- creates at current location
$ mkdir /root/user/test_dir
$ mkdir –p /root/oracle/sapdata1 --- if the parent directory does not exists creates
$ mkdir –m 755 /oracle/sapdata2 --- creates sapdata2 with 755 permissions.
$ mkdir test_dir1 test_dir2 test_dir3 --- creates multiple directories
$ mkdir –p Shradda/{Linux/{Debian,Ubuntu},Solaris/zones/{globale,non-global}}
$ tree /oracle --- to see the subdirectories or directory structure.

Anil Vajragiri Page 9


RED HAT LINUX

# rm
-i --- interactively
r --- recursively
-v --- verbose
-f --- frocebly
$ rm /root/test1 --- removes file test1
$ rmdir --- removes empty directory
$ rm –r --- remove non-empty directory
$ rm –rf – removes non-empty directory --- (beware this is a destructive command)

# ls
--ls is used to list the files and directories.
Options : -a/B/d/F/i/l/m/n/o/p/Q/r/s/t/1/--full-time
-a --- shows all files including hidden files
-B --- shows other than backup files
-d --- shows current directory
-F --- shows diff between files and directories
-i --- shows the inode no of files and directories
-l --- long listing of files and directories
-m --- prints fields separated by comma
-n --- shows userid and groupid
-o --- shows 8 filed output other than group information
-r --- shows in reverse order
-t --- current modification time
--full-time --- shows 11 fields output
-1 --- shows all files and directories in single line

#cp (copy)
Copies files and directories from source to the target location. Copies with 3
possibilities.
1. file to file
2. file to directory
3. Directory to directory
-i --- interactively
-v --- verbose
-r --- recursively
-f --- forcibly
-b --- takes the backup and copy
$ cp –v testfile1 testfile2
$ cp –i testfile1 testdir1
$ cp –rf testdir1 testdir2
$ cp –b testfile1 testdir1
$ cp file1 file2 file3 testdir1 --- copies file1,file2 file3 to the testdire1

# mv (move or rename)
Move command is used to move a file or directory from one location to other
location or rename file or directory with other name.

1. $ mv file1 /testdir/ --- moved to testdir


2. $ mv file1 file2 --- renames file1 to file2

Anil Vajragiri Page 10


RED HAT LINUX

3. $ mv /dir1 /testdir1 --- move /dir1 to new location under /testdir1 if testdir
exists else renames /dir1 to /testdir1

# VI editor

1. Esc mode (command line)


2. Insert mode
3. Colon mode (last line)

l --- moves 1 char right


h --- moves 1 char left
j --- moves 1 char down
k --- moves 1 char up
$ --- moves cursor to the end of the record
^ --- moves cursor to the start of the record
W --- moves 1 word forword
b --- moves 1 word backword
nw --- moves no of words forword (3w)
nb --- moves no of words backword (5b)
e --- moves the corsor to the end of the word
gg --- moves cursor to the start of the file
10gg ---moves 10 lines up
G --- moves cursor to the end of the file
5G --- moves 5lines down word
H --- moves cursor to the start of the screen
L --- moves cursor to the end of the screen
M --- moves cursor to the middle fo the screen
r --- replaces cursor position character
R --- replaces cursor position record

Deleting
x --- deletes cursor position character
X --- deleted before cursor position character
dd --- deleted cursor position record
dw --- deletes cursor position word forward
db --- deleted cursor position record backword
d$ --- deletes cursor position to the end of the record
d^ --- deleted cursor position to the start of the record
dG --- deletes cursor position to the end of the file
dgg --- deletes cursor position to start of the file
ndd --- deletes specified no of lines

copying
yy --- yanks cursor position record
yw --- copies oneword forward
yb --- copies oneword backword
y$ --- copies cursor position to the end of the record
y^ --- copies cursor position to the start of the record
ygg --- copies cursor to the start of the file

Anil Vajragiri Page 11


RED HAT LINUX

yG --- copies cursor position to the end of the file.


p --- pastes below corsor position
P --- pastes above cursor position

Inserting
a --- cursor moves to the next word and inserts
A --- cursor moves end of the record and inserts
i --- cursor will be same position and inserts
I --- cursor moves start of the record and inserts
O --- inserts new line above cursor position
o --- inserts new line below cursor position
cc --- deletes cursor position record and inserts
cw --- deletes cursor position word and inserts

colon mode
:w saves
:wq saves and quits
:wq! Saves and quits forcefully
:q quits without saving
:q! quits forcefully without saving
:se nu --- sets no to the records
:se nonu --- unsets the no to the records
:/word --- searches word
:?word --- searches for word
:se ic --- sets ignore case
:se noic --- unsets ignore case
:1,$s/unix/genunix/g --- replaces unix by genunix
:se ai sets auto indentation
:se noai --- unsets auto indentation
:abbr --- ab set abbreviation
:unabbr --- unsets abbreviation
:!command --- excutes the command in editor mode.

# uname
Uname prints system information
$ uname –n --- prints node name information
$ uname –a --- shows all information
$ uname –r --- System Kernel Version
$ uname -v --- Shows Kernel release version
$ uname –s --- shows OS
$ uname –m --- Shows mechine name
$ uname –o Prints OS name

Anil Vajragiri Page 12


RED HAT LINUX

#who
$ who to know all users login information
$ who –iH shows login information with headings.
$ who –m shows information with host name
$ who –q shows all users login count
$ who –r shows run level information
$ who –a prints all possible information
$ who –b prints last reboot time
$ who –d prints dead processes
$ who –u prints the login users info

# cal
$ cal shows current month
$ cal -3 shows previous, current and future month details
$ cal –y shows current year details
$ cal 2008 shows year 2008

# finger
Shows the user details.
$ finger prints user information
$ finger –l user prints User Information
$ finger -s prints user login name, real name and terminal name.

# date
$ date --- displays the date
$ date +%a --- day of the week in short (Sun)
$ date +A --- day of the week in long form (Sunday)
$ date +%b --- month in short (Mar)
$ date +%B --- month in long form (March)
$ date +%y --- year in short (15)
$ date +%Y --- year in long form (2015)
$ date +%x --- date (06/21/2015)
$ date +%X --- time in 12 hr format (06:30:41 PM)
$ date +%T --- time in 24 hr format
$ date +%d --- day in short (21)
$ date +%D ---date in long format (21/06/15)

All possible options


# date
Wed Jul 29 16:17:09 CEST 2015
# date +%a
Wed
# date +%A
Wednesday
# date +%b
Jul
# date +%B
July
# date +%Y

Anil Vajragiri Page 13


RED HAT LINUX

2015
# date +%y
15
# date +%c
Wed Jul 29 16:18:11 2015
# date +%C
20
# date +%d
29
# date +%D
07/29/15
# date +%m
07
# date +%e
29
# date +%E
%E
# date +%F
2015-07-29
# date +%g
15
# date +%G
2015
# date +%H
16
# date +%h
Jul
# date +%I
04
# date +%k
16
# date +%M
21
# date +%m
07
# date +%M
22
# date +%n
# date +%p
PM
# date +%P
pm
# date +%r
04:23:32 PM
# date +%R
16:23
# date +%S
49
# date +%T
16:24:28
# date +%x

Anil Vajragiri Page 14


RED HAT LINUX

07/29/15
# date +%X
16:25:19
# date +%z
+0200
# date +%Z
CEST
#

PERMISSIONS
Permissions are the access authority given to a file or a directory for owner, group
and others. Permissions are read (r) with value of 4, write (w) with value of 2 and
execute permission (x) with value of 1. Total 7.
Default permissions for a normal file – 644 (full permissions 666)
Default permissions for a directory – 755 (full permissions 777)
The default permissions are set when file or directory created due to umask value
022.
File --- 666 – 022=644
Directory --- 777 – 022=755

Types of files
1. Ordinary file
2. Directory
3. Link file
4. Block special file
5. Character special file

# chmod
Chmod is to change the permissions of a file or a directory
Permissions can be changed
a. Numeric method
b. Symbolic method
Numer Method:
$ chmod 600 testfile1 (user –6, group-0, others-0 permissions)
$ chmod 750 testdir1 ( user – 7, group-5, others-0 permissions)
Symbolic Method:
Using symbols permissions can be assigned to a file or directory
+ adding permission
– deleting permission
a all
= equal value
$ chmod u+w,g-e,o+r testfile1
$ chmod ugo+rwe testfile
$ chmod ugo=r testfile

Anil Vajragiri Page 15


RED HAT LINUX

LINKING
Linking is a relationship between files. Files are linked across the directories or
paths to
1. Hide the visibility of actual path.
2. To hide the visibility of actual file.
3. To reduce the risk of deletion
4. To provide the access to the files
There are two types of lining
a. Soft link
b. Hard link
c.
Hard link:
Inode number is same, data is same. In short it is the other name given to a file.
If source is deleted still the data is safe. We cannot find which is source and with is
target.
$ ln testfile1 testfile_link
$ ln testfile1 testfile_l1 testfile_l2 ( testfile1 is source; testfile_l1 and testfile_l2 are links)

Soft link:
We can create the soft link across the directory paths.
Soft links are created both for directories and files.
Inode numbers are different for the source and target.
If the date in source is deleted then the date in target is lost.
Target contains the inode number of source instead of date.
We cannot chage the permissions of the target file.
$ ln –s /var/logs/authlog /user/vajrag/authlog

PATH
PATH is the location of file or a directory
1. Absolute path
2. Relative path

Absolute path is the complete path given basing on its location (Complete path)
Relative path is the path basing the user location or present working directory.
$ cp /var/log/authlog /user/vajrag/ -- Absolute path
$ cd /var/log/authlog ./../dir1 – Relative path
(. Is present directory .. is parent directory to pwd.)
Authlog is copied to /var/dir1/

Redirections
Its redirecting the standard output to the standard input or vice versa.
monitor are typical output device and keyboard is the standard input device.
There are sysmbols that represents the redirections.
< O r0 Is the standard output
> or 1 is the standard input

2 or 2> is the standard error


$ cat > file1
Thisis file2
Ctrl+D
$ cat < file1 --- to see the data

Anil Vajragiri Page 16


RED HAT LINUX

$ cat file1 >> file_1


$ cat file1 > file2
$ cat >> file1 < file3
$ cat < file1 > file4
$ cat file5 < file6
$ cat * 2> /dev/null
$ cat * 2> /log/error_file >2&1

# kill
Kill command terminates a process. Kill command can be used either with process
name or by the process id. The default signal for kill is TERM (which will terminate
or "kill" the process). Use -l or -Lto list available signals. Particularly useful signals
include HUP, INT, KILL, STOP, CONT, and 0. Alternate signals may be specified in
three ways: -9, -SIGKILL or -KILL. Negative PID (process ID) values may be used to
choose whole process groups; see thePGID column in the output of the ps command.
A PID of -1 is special; it indicates all processes except two: the kill process itself,
and init.

$ kill -9 0710
$ kill –SIGKILL 0710
$ kill –SUGHUP 0720

The kill command accepts either the signal number or name (signals have
both a number and name that can be referenced). The name must be in all
caps.

# pkill
$ pkill command is like kill command but takes partial names.
$ pkill -9 -u USERNAME'

SIGHUP - The SIGHUP signal disconnects a process from the parent process. This an
also be used to restart processes. For example, "killall -SIGUP compiz" will restart
Compiz. This is usefulfordaemonswithmemoryleaks.

SIGINT - This signal is the same as pressing ctrl-c. On some systems, "delete" + "break"
sends the same signal to the process. The process is interrupted and stopped.
However, the process can ignore this signal.

SIGQUIT - This is like SIGINT with the ability to make the process produce a core
dump.

Anil Vajragiri Page 17


RED HAT LINUX

SIGILL - When a process performs a faulty, forbidden, or unknown function, the


system sends the SIGILL signal to the process. This is the ILLegal SIGnal.

SIGTRAP - This signal is used for debugging purposes. When a process has performed
an action or a condition is met that a debugger is waiting for, this signal will be sent
to the process.

SIGABRT - This kill signal is the abort signal. Typically, a process will initiate this
kill signal on itself.

SIGBUS - When a process is sent the SIGBUS signal, it is because the process caused a
bus error. Commonly, these bus errors are due to a process trying to use fake
physical addresses or the process has its memory alignment set incorrectly.
SIGFPE - Processes that divide by zero are killed using SIGFPE. Imagine if humans
got the death penalty for such math. NOTE: The author of this article was recently
drug out to the street and shot for dividing by zero.

SIGKILL - The SIGKILL signal forces the process to stop executing immediately. The
program cannot ignore this signal. This process does not get to clean-up either.

SIGUSR1 - This indicates a user-defined condition. This signal can be set by the user
by programming the commands in sigusr1.c. This requires the programmer to know
C/C++.

SIGSEGV - When an application has a segmentation violation, this signal is sent to


the process.

SIGUSR2 - This indicates a user-defined condition.

SIGPIPE - When a process tries to write to a pipe that lacks an end connected to a
reader, this signal is sent to the process. A reader is a process that reads data at the
end of a pipe.

SIGALRM - SIGALRM is sent when the real time or clock time timer expires.

SIGTERM - This signal requests a process to stop running. This signal can be ignored.
The process is given time to gracefully shutdown. When a program gracefully shuts
down, that means it is given time to save its progress and release resources. In other
words, it is not forced to stop. SIGINT is very similar to SIGTERM.

SIGCHLD - When a parent process loses its child process, the parent process is sent
the SIGCHLD signal. This cleans up resources used by the child process. In
computers, a child process is a process started by another process know as a parent.

SIGCONT - To make processes continue executing after being paused by the SIGTSTP
or SIGSTOP signal, send the SIGCONT signal to the paused process. This is the
CONTinue SIGnal. This signal is beneficial to Unix job control (executing
background tasks).
SIGSTOP - This signal makes the operating system pause a process's execution. The
process cannot ignore the signal.

Anil Vajragiri Page 18


RED HAT LINUX

SIGTSTP - This signal is like pressing ctrl-z. This makes a request to the terminal
containing the process to ask the process to stop temporarily. The process can ignore
the request.

SIGTTIN - When a process attempts to read from a tty (computer terminal), the
process receives this signal.

SIGTTOU - When a process attempts to write from a tty (computer terminal), the
process receives this signal.

SIGURG - When a process has urgent data to be read or the data is very large, the
SIGURG signal is sent to the process.

SIGXCPU - When a process uses the CPU past the allotted time, the system sends the
process this signal. SIGXCPU acts like a warning; the process has time to save the
progress (if possible) and close before the system kills the process with SIGKILL.

SIGXFSZ - Filesystems have a limit to how large a file can be made. When a program
tries to violate this limit, the system will send that process the SIGXFSZ signal.

SIGVTALRM - SIGVTALRM is sent when CPU time used by the process elapses.

SIGPROF - SIGPROF is sent when CPU time used by the process and by the system
on behalf of the process elapses.

SIGWINCH - When a process is in a terminal that changes its size, the process
receives this signal.

SIGIO - Alias to SIGPOLL or at least behaves much like SIGPOLL.

SIGPWR - Power failures will cause the system to send this signal to processes (if the
system is still on).

SIGSYS - Processes that give a system call an invalid parameter will receive this
signal.

SIGRTMIN* - This is a set of signals that varies between systems. They are labeled
SIGRTMIN+1, SIGRTMIN+2, SIGRTMIN+3, ......., and so on (usually up to 15). These
are user-defined signals; they must be programmed in the Linux kernel's source code.
That would require the user to know C/C++.

SIGRTMAX* - This is a set of signals that varies between systems. They are labeled
SIGRTMAX-1, SIGRTMAX-2, SIGRTMAX-3, ......., and so on (usually up to 14). These
are user-defined signals; they must be programmed in the Linux kernel's source code.
That would require the user to know C/C++.

SIGEMT - Processes receive this signal when an emulator trap occurs.

SIGINFO - Terminals may sometimes send status requests to processes. When this
happens, processes will also receive this signal.

SIGLOST - Processes trying to access locked files will get this signal.

Anil Vajragiri Page 19


RED HAT LINUX

SIGPOLL - When a process causes an asynchronous I/O event, that process is sent the
SIGPOLL signal.

# ps
The ps command on Linux is one of the most basic commands for viewing the
processes running on the system. It provides a snapshot of the current processes
along with detailed information like user id, cpu usage, memory usage, command
name etc.

$ ps ux – displays list of all processes


$ ps –ef

Use the "u" option or "-f" option to display detailed information about the processes
$ ps aux
$ ps –ef –f
$ ps –f –u username --- displays all process of specified user.

To search the processes by their name or command use the "-C" option followed by
the search term.
$ ps -C apache2
PID TTY TIME CMD
2359 ? 00:00:00 apache2
4524 ? 00:00:00 apache2
4525 ? 00:00:00 apache2

To display processes by process id, use the "-p" option and provides the process ids
separated by comma.
$ ps -f -p 3150,7298,6544

The "-C" must be provided with the exact process name and it cannot actually search
with a partial name or wildcard.

Sorting process by specific values


$ ps aux --sort=-pcpu,+pmem

Display child processes of a parent process


Here is an example of finding all forked apache processes.

$ ps -o pid,uname,comm -C apache2
PID USER COMMAND
2359 root apache2
4524 www-data apache2
4525 www-data apache2
4526 www-data apache2
4527 www-data apache2
4528 www-data apache

The next command lists all child apache2 processes using the pid of the main
apache2 process
$ ps --ppid 2359

Anil Vajragiri Page 20


RED HAT LINUX

PID TTY TIME CMD


4524 ? 00:00:00 apache2
4525 ? 00:00:00 apache2
4526 ? 00:00:00 apache2
4527 ? 00:00:00 apache2
4528 ? 00:00:00 apache22

The following command shows only the pid, username, cpu, memory and command
columns.
$ ps -e -o pid,uname,pcpu,pmem,comm

CHAPTER 4
FILTERS

FILTER is a command which takes input from standard input manipulates it and
writes to standard output.
a. Simple filters
b. Advanced filters

Simple filters:
1. Head
2. Tail
3. More
4. Less
5. Cut
6. Paste
7. Sort
8. Uniq
9. Tr
10. Tee

Advanced filters:
1. grep
2. sed
3. awk

# head
$ head file1 --- displays by default 10 lines of starting of a file
$ head -5 file1 --- displays only first 5 lines
$ head -20 file1 --- displays first 20 lines of a file

# tail
$ tail /testdir/testfile1 --- displays last 10 lines by default
$ tail -7 /test/testfile1 --- displays last 7 lines of a file
$ tail -20 /testdir/testfile --- displays last 20 lines of a file.

Anil Vajragiri Page 21


RED HAT LINUX

# more
The more command displays the file called name in the screen. The RETURN key
displays the next line of the file. The spacebar displays the next screen of the file.
$ cat file1 | more

# less
Less is similar to more command, but less allows both forward and backward
movements. Once you’ve opened a log file (or any file) using less file-name, use the
following keys to search. Please note that the match will be highlighted
automatically by default.
Forward Search
/ – search for a pattern which will take you to the next occurrence.
n – for next match in forward
N – for previous match in backward

Backward Search
? – search for a pattern which will take you to the previous occurrence.
n – for next match in backward direction
N – for previous match in forward direction
$ less file1
$ cat file1 | less

#wc
Word count is used to count the number of lines, number of words and number of
characters in a file.
$ wc –c file1 – displays the no of character of a file
$ wc –w file1 --- displays the no of words in a file
$ wc –l file1 --- counts no of lines in a file.
$ wc –cwl file1 --- counts characters, words and lines of a file.
$ wc file1 --- counts characters, words and lines of a file.

# cut
Used to cut the characters as desired.
--c ---cuts the characters
--d --- specifies delimiter
--f --- required field

File1:
Anil:Doctor:90000
Chaitanya:Actor:200000
Akshya:Engineer:100000
Ananya:Doctor:300000

$ cut –c1 file1 --- cuts first character


$ cut –c1-3 file1--- cuts firest 3 characters
$ cut –d”:” –f2 file1 --- cuts the 2nd field
$ cut –d”:” –f2 file1 | cut –c1-4

# sort

Anil Vajragiri Page 22


RED HAT LINUX

Used to arrange the records of a file


-r --- sorts in reverse order
-t --- field separator
-k --- specifies the field
-n --- sorts on numeric
$ sort –n filename --- sorts based on numeric value
$ sort –d filename --- sorts on dictionary format
$ sort –t”:” –k2 file1
$ sort –nrk 1,1 file1

# tee
Command used to create a multiple files with same data.
Used to divert to standard output also to standard input.

$ tee test1 test2 test3


$ cat test5|tee test6

# tr
Translates the upper to lower and lower to upper case.
Squeezes the multiple characters
Deletes the character
$ tr “[a-z]” “[A-Z]” < testfile
$ tr “[A-Z]” “[a-z]” < testfile
$ tr –s “e” testfile --- squeezes the multiple ‘e’
$ tr –d “e” testfile --- deletes the character ‘e’

Anil Vajragiri Page 23


RED HAT LINUX

CHAPTER 5
Advanced Filters
#grep
Global search for regular expression.
We can search record by record.

$ grep –i anil testfile1 --- case sensitive


$ grep –w anil testfile --- exact match word
$ grep –l anil * --- displays the matching word file name
$ grep –s anil testfile --- squeezes the errors
$ grep –h anil testfile ---shows word output
$ grep –r anil /testdir --- searches recursively for matching word
$ grep –e anil -e sunil testfile --- searches multiple words
$ grep –E anil | sunil testfile --- searches multiple words
$ grep –v anil testfile --- searches other than ‘anil’
$ grep –A1 anil testfile --- anil record and below record
$ grep –B2 anil testfile --- anil record and above two records
$ grep –C3 anil testfile --- one record above and one record below
$ grep “^a” testfile --- displays a word starting with ‘a’
$ grep “g$” testfile --- home --- ends with word ‘g’

# sed
Stream editor for filtering and transforming test
$ sed <option> <action> filename
-n --- to suppress multiple expressions
-e --- to search multiple expressions
-p --- printing
-d --- deleting
-s --- substituting

print
$ sed ‘p’ test1
$ sed –n ‘p’ test1
$ sed –ne ‘1p’ –e ‘2p’ testfile

Anil Vajragiri Page 24


RED HAT LINUX

$ sed –ne ‘/anil/p’ –e ‘/chai/p’ testfile


$ sed –n ‘1-3/p’ testfile
$ sed –n ‘1,4p’ testfile
$ sed –n ‘/anil/,/ananya/p’ testfile

delete
$ sed ‘1d’ testfile
$ sed –e ‘1d’ –e ‘3d’ testfile
$ sed –e ‘/sunil/p’ –e ‘/anil/p’ testfile
Substitute
$ sed ‘s/anil/anilkumar/1’ testfile
$ sed ‘s/anil/anilkumar/g’ testfile
$ sed ‘1,$s/anil/sai/g’ testfile
$ sed ‘1,4/anil/sai/g’ testfile

# awk
Aho, wenberger and kerneghan developed the filter named after them.

Operators
>= greater than equal
> greater than
< less than
<= less than eqal
== equal
!= not equal
|| or
&& and
NR No of records
NF No of fields
$ specified filed
~ matching with
!~ not matching

$ awk ‘/sai/{print}’ testfile


$ awk ‘{print}’ testfile
$ awk –F”:” ‘/sai/{print $1}’ testfile
$ awk –F”:” ‘{print $2}’ testfile
$ awk –F”:” ‘{print $1 “salary is” $3}’ testfile

$ awk ‘NR>3 {print}’ testfile


$ awk –F”:” ‘NR>={print}’ testfile
$ awk –F”:” ‘NR==1{print}’ testfile
$ awk ‘NR==1 && NR==5{print}’ testfile
$ awk ‘{print NR,NF}’ testfile
$ awk ‘{print NR,$0}’ testfile
$ awk –F”:” ‘$2 ~/teacher/{print}’ testfile
$ awk –F”:” ‘$2 !~/teacher/{print}’ testfile

# find
Search for files in directory hierarchy.
-type

Anil Vajragiri Page 25


RED HAT LINUX

-name
-inum
-empty
-size
-mindepth
-maxdepth
-perm
-exec
-ctime
-mtime
-atime

$ find / -type f --- searches for all files uder root


$ find ~ -type d --- searches for directories under user root directory
$ find . –name file1 --- searches for a file1 in present directory
$ find . –inum 7654 --- searchs for file or dir with inode no 7654
$ find / -empty --- searches for empty files
$ find / -type f –name test1 –mindepth 4
$ find / -type f –perm 666
$ find / -type f -perm 755 –exec ls –l {} \;
$ find / -type f –perm 006 –exec rm {} \;
$ find /oracle/P2X –size +10000000c –exec ls –l {} \;
$ find /oracle –ctime -15 –exec ls –l {} \;

Anil Vajragiri Page 26


RED HAT LINUX

Anil Vajragiri Page 27


RED HAT LINUX

Anil Vajragiri Page 28

Vous aimerez peut-être aussi