Professional Documents
Culture Documents
REDHat
REDHat
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
SCHEDULING TASKS:
at: scheduling one time jobs
at <time>
at -l (or) atq
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
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>
locate -r '\.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
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
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)
Allocates a free inode number, placing a new entry in the inode table
MV AND INODES
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!
RM AND INODES
THE RM COMMAND:
Decrements the link count, thus freeing the inode number to be reused
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
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