Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

PROCESS:

A process is a set of instructions loaded into memory


Numeric Process ID (PID) used for identification
UID, GID and SELinux context determines filesystem access
Normally inherited from the executing user
PS
ps - report a snapshot of the current processes.
Shows processes from the current terminal by default
-a includes processes on all terminals
-x includes processes not attached to terminals ie., daemon process
-u prints process owner information
-f prints process parentage
-o PROPERTY,... prints custom information:
pid, comm, %cpu, %mem, state, tty, euser, ruser
Note: There are other process states listed in "man ps"
PROCESS STATES:
* Running - the process is actively using cpu
* Sleeping - in memory but not doing anything
* uninterruptable sleep - process is sleeping and can not be woken
up until an event occurs
* Zombie

- just before a process dies, it sends a signal to its


parent and waits for an acknowledgement before
terminating

FINDING PROCESS ID'S


ps axo pid,comm | grep gnome-terminal
pgrep gnome-terminal
pidof gnome-terminal
pgrep -u root sshd

will only list the processes called sshd AND owned by root.
pgrep -u root,daemon
will list the processes owned by root OR daemon.
Note: pgrep looks through the currently running processes and lists the process IDs
which matches the selection criteria to stdout.
SIGNALS:
kill [ -s signal | -p ] [ -a ] [ -- ] pid ...
kill -l [ signal ]
The command kill sends the specified signal to the specified process or process
group. If no signal is specified, the TERM signal is sent. The TERM signal will kill
processes which do not catch this signal.
-s signal
Specify the signal to send. The signal may be given as a signal name or Number.
-l Print a list of signal names
If PID is positive, the signal is sent to the process with the process ID PID. If PID
is zero, the signal is sent to all processes in the process group of the current process. If
PID is -1, the signal is sent to all processes for which the user has permission to send a
signal. If PID is less than -1, the signal is sent to all processes in the process group that
equals the absolute value of PID.
Signals are specified by name or number when sent:
Signal 15, TERM (default) - Terminate cleanly
Signal 9, KILL - Terminate immediately
Signal 1, HUP - Re-read configuration files
man 7 signal shows complete list
SENDING SIGNALS TO PROCESSES:
By PID: kill [signal] pid ...
By Name: killall [signal] comm ...
By pattern: pkill [-signal] pattern
Note: Kill may send many signals, but process only respond to the signals they have

been programmed to recognize.


HUP - Most services are programmed to reload their configuration when they
receive a HUP
TERM - The process is shutdown cleanly: that is, child process are terminated
first and any pending I/O operations are completed.
KILL - If the process will not respond to a TERM signal, the KILL can be used.
However, the process may not be ended cleanly. The KILL signal should
be used only if a process will not respond to a Ctrl+C or a TERM signal.
Using KILL signals on a routine basis may cause zombie process and data
loss
SCHEDULING PRIORITY
Every running process has a scheduling priority: a ranking among running
processes determining which should get the entire attention of the processor.
User can change priority by setting 'niceness' value
Values range from -20(least nice, highpriority) to 19 (most nice, lowest priority)
but default to 0
Viewed with ps -o comm,nice
Non-privileged users may not set niceness value to less than zero: that is they
may not request a higher than normal priority for their processes
TO SET THE NICENESS VALUE TO A SPECIFIC VALUE WHEN STARTING A PROCESS,
nice - run a program with modified scheduling priority
nice -n <priority> <command>
nice -n 5 command
renice - alter priority of running processes
renice <nice value> <PID>
renice -15 -p <PID>
top - The top program provides a dynamic real-time view of a running system
gnome-system-monitor - The graphical program provides a real-time view of a
running system

SCHEDULING TASKS:
at: scheduling one time jobs
at <time>

==> create a scheduling to run at once

at -l (or) atq

==> list scheduling

at -c <job no> ==> details about scheduling


at -d <job no>
(or)
atrm <job no>

==> delete the scheduling

service atd start/restart/reload


chkconfig atd on
Ex:
at 0200
at 5:30pm December 4
at 9 am monday
at midnight + 15 minutes
at now+4 minutes
CRONTAB:
crontab -eu <username>

==> create/edit crontab

crontab -lu <username>

==> lists user crontab

crontab -ru <username>

==> removes crontab

field
allowed values
-----------------minute
0-59
hour
0-23
day of month 1-31
month
1-12
day of week 0-7 (0 or 7 is Sun, or use names)
A field may be an asterisk (*), which always stands for first-last.
Ex:
RUN AT 2:15PM ON THE FIRST OF EVERY MONTH

crontab -eu <uname>


15 14 1 * *

echo "this is test" > /dev/tty1

service crond start/restart/reload


chkconfig crond on
who

who - show who is logged on

w
w - Show who is logged on and what they are doing
whoami
Print the user name associated with the current effective user ID
which
which - shows the full path of (shell) commands
which fdisk
/sbin/fdisk
last, lastb
last, lastb - show listing of last logged in users

BASH VARIABLES:
HI="Hello, and welcome to $(hostname)."
$ echo $HI
Hello, and welcome to stationX
LOCAL VARIABLES & ENVIRONMENT VARIABLES:
Two types of variables exist: local variables, also called shell variables, and
environment variables. The difference between the two is that the shell will pass the
environment variables on to commands that it calls, but it will

not

pass

on

local

variables. As a result, local variables are used to configure the shell itself, while
environment variables are used to configure other

COMMANDS
set | less
env | less
CONFIGURATION VARIABLES
PS1: Appearance of the bash prompt
PS1="\u@\h:\w <\!>\$"
\h hostname
\u user name
\w the current working directory
\! history number of the current command
\$ shows $ when non-privileged user, # when root user.
Note: For permenant settings edit the /etc/bashrc file
PATH: Directories to look for executables in
EDITOR: Default text editor
HISTFILESIZE: Number of commands in bash history
INFORMATION VARIABLES
HOME: User's home directory
EUID: User's effective UID

ALIAS
TEMPERORARY
alias c=clear
PERMENANTLY
vim /root/.bashrc
alias cp='cp -i'
alias mv='mv -i'
alias c='clear'

Note: This is entry will be activated only after logout of that session.
LOCATE
locate <file name>
The locate database must be generated by an administrator running the
'updatedb' command
Database updates can be also automated by an administrator enabling
the DAILY_UPDATE option in /etc/updatedb.conf
locate -i <file name>

==> case-insensitive search

locate -n X <file name>

==> lists only first X matches

locate -r '\.txt$'

==> searches for file ending in .txt

FIND
Slower but more accurate than locate
May only search directories where the user has read and execute permission
find <location> -name <file name>
find /etc -name passwd
BASIC FIND EXAMPLES:
find -name snow.png
Search for files named snow.png
find -iname snow.png
Case-insensitive search for files named snow.png, Snow.png, SNOW.PNG, etc
find -user joe -group joe
Search for files owned by the user joe and the group joe
FIND AND LOGICAL OPERATORS:
Criteria are ANDed together by default.
Can be OR'd or negated with -o and -not
Parentheses can be used to determine logic order, but must be escaped

in bash.
find -user joe -not -group joe
find -user joe -o -user jane
find -not \( -user joe -o -user jane \)
CAN MATCH OWNERSHIP BY NAME OR ID
find / -user joe -o -uid 500
CAN MATCH OCTAL OR SYMBOLIC PERMISSIONS
find -perm 755 matches if mode is exactly 755
find -perm +222 matches if anyone can write
find -perm -222 matches if everyone can write
find -perm -002 matches if other can write
FIND AND NUMERIC CRITERIA:
find -size 1024k
Files with a size of exactly 1 megabyte
find -size +1024k
Files with a size over 1 megabyte
find -size -1024k
Files with a size less than 1 megabyte
FIND CAN MATCH BY INODE TIMESTAMPS:
atime when file was last read
mtime when file data last changed
ctime when file data or metadata last changed
Value given is in days
find -ctime -10
Files modified less than 10 days ago

EXECUTING COMMANDS WITH FIND:


Commands can be executed on found files
Command must be preceded with -exec or -ok
ok prompts before acting on each file
Command must end with Space\;
Can use {} as a filename placeholder
find -size +102400k -ok gzip {} \;
FIND EXECUTION EXAMPLES
find -name "*.conf" -exec cp {} {}.orig \;
Back up configuration files, adding a .orig extension
find /tmp -ctime +3 -user joe -ok rm {} \;
Prompt to remove Joe's tmp files that are over 3 days old
find ~ -perm +o+w -exec chmod o-w {} \;
Fix other-writable files in your home directory
GNOME SEARCH TOOL:
Places -> Search for Files

WEBCLIENTS:
web browser by default
http://www.google.co.in
links / elinks in the command mode
links www.redhat.com
Download webpage in command mode using the command:
wget www.google.com
SSH: secure remote shell
ssh [user@]hostname
ssh [user@]hostname command
Ex: ssh root@192.168.0.1

SCP: secure copy


scp <source> <destination>
Remote files can be specified using:
Use -r to enable recursion
Use -p to preserve times and permissions
Use -C to compress datastream
Ex:
scp root@192.168.0.4:/etc/passwd /mnt
scp -r root@192.168.0.2:/boot/* /opt
scp -r /boot/* root@192.168.0.3:/mnt
ping - send ICMP ECHO_REQUEST to network hosts
ping <ip addr>
ping <fqdn>
ping 192.168.0.254
ping -c5 192.168.0.254
pup

Applications->System Tools->Software Updater


List and install software updates

pirut

Applications->Add/Remove Software
View, install and un-install other packages

INODES:
An inode table contains a list of all files in an ext2 or ext3 filesystem
An inode (index node) is an entry in the table, containing information
about a file (the metadata), including:
file type, permissions, UID, GID
the link count (count of path names pointing to this file)

the file's size and various time stamps


CP AND INODES
THE CP COMMAND:
o

Allocates a free inode number, placing a new entry in the inode table

Creates a entry in the directory, associating a name with the inode


number

Copies data into the new file

MV AND INODES

If the destination of the mv command is on the same file system as the


source, the mv command:

Creates a new directory entry with the new file name

Deletes the old directory entry with the old file name

Has no impact on the inode table (except for a time stamp) or the location of
data on the disk: no data is moved!

If the destination is a different filesystem, mv acts as a copy and remove

RM AND INODES
THE RM COMMAND:

Decrements the link count, thus freeing the inode number to be reused

Places data blocks on the free list

Removes the directory entry

Data is not actually removed, but will be overwritten when the data blocks
are used by another file

HARDLINK:
A hard link adds an additional pathname to reference a single file
One physical file on the filesystem
Each directory references the same inode number

Increments the link count


The rm command decrements the link count
File exists as long as at least one link remains
When the link count is zero, the file is removed
Cannot span drives or partitions
Syntax:
ln filename [linkname]
SYMBOLIC (OR SOFT) LINKS
A symbolic link points to another file
ls -l displays the link name and the referenced file
lrwxrwxrwx 1 joe joe 11 Sep 25 18:02 pf -> /etc/passwd
File type: l for symbolic link
The content of a symbolic link is the name of the file that it references
Syntax:
ln -s filename linkname
df - Reports disk space usage
Reports total kilobytes, kilobytes used, kilobytes free per file system
-h and -H display sizes in easier to read units
du - Reports disk space usage
Reports kilobytes used per directory
Includes subtotals for each subdirectory
-s option only reports single directory summary
Also takes -h and -H options
baobab - Reports disk space usage graphically
MOUNT CDROM:
mount /media/cdrom /mnt
mount /dev/cdrom /mnt

MOUNT PEN DRIVE


mount /dev/sd(b or b1) /mnt
mount /dev/sdb1 /opt
eject

- eject removable media

eject -t - closes cd drive tray


TAR:
tar -cvf <file name> <source dir name>
-c create
-v verbose
-f archive file name
-x extract
Ex: tar -cvf etc.tar /etc ==> creates tar file
tar -xvf etc.tar

==> extracts tar file

GZIP:
gzip <file with tar extension>
Ex: gzip etc.tar
ls
etc.tar.gz
GUNZIP:
gunzip <file name>
Ex: gunzip etc.tar.gz
BZIP2:
bzip2 <file with tar extension>
Ex: bzip2 etc.tar
BUNZIP2:
bunzip2 <file name>
Ex: bunzip2 etc.tar.bz2

You might also like