Professional Documents
Culture Documents
RH033 Red Hat Linux Essential:
RedHat Linux Family
A) Redhat Enterprise Linux Advance Server :
The topoftheline Red Hat Enterprise Linux Solution, this product supports
the largest x86compatible servers and is available with the highest levels of
support.
B) Redhat Enterprise Linux Enterprise Server :
For entrylevel or midrange department servers. Red Hat
Enterprise Linux ES provides the same core capabilities as Advance
Server for systems with up to two physical CPU’s and up to 8 GB of
main memory.
C) Redhat Enterprise Linux Workstation :
: Commands :
1) #mkdir <folder name>
2) #mkdir –p <parent folder name>/<subfolder name>
p = create parent & sub folder even if it is not there
3) #cat > new filename (this is allow to create file & to save file press
Ctlr+d)
4) #cat filename (to view files content)
5) #cat filename > newfile (this will append content of previous file to new
file)
6) #cat >> filename (this will append to the file & to save file press
ctlr+d)
7) #date (To display date and time)
8) #date –s 20041209 (yyyymmdd) (this will change the current date)
9) #date –s 18:00 (this is will change time)
10) #date MMddhhmmyy (it chages date & time together)
MM : Month
dd : Date
hh : Hours
mm : Minutes
yy : Year
11) #date +”Today is %A, %B , %d , %Y . %n The time now is %r , %z .”
Today is Sunday, may 05, 2005.
The time now is 02:54:45 PM, EDT.
12) #cal 12 2005 (12 represents month, 2005 represents year)
13) #cal (It will show you current cal)
14) #cal 2006
13) #cp sam.txt /root (This is will copy sam.txt file to root folder)
14) #cp filename filename (This is will copy the content of one file to
another)
15) #cp –r i –p /onefolder /secondfolder
i = Interactive ask before overwriting
r = recursive (The content of sub folders and files)
p = preserve permission
16) #pwd (To see the status of present working dir)
17) #cd .. (This is allow to come one step back)
18) #cd (If this command is executed by any user then he or
she
will be switch automatically to home dir for e.g. /root for root
user)
19) #cd / (This is will take you root of this current partition)
20 ) #cd ~ (If this command is executed by any user then he or
she
will be switch automatically to home dir for e.g. /root for root
user)
21) #cd – (It will switch u to previous working directory)
22) #cd ../root/sameer/test (This will first take u back one step and then it
will switch u to particular folder.)
Note : . represents to the current dir
.. represents to the parent dir
There are two types of path 1. is relative path which represents . and 2.is
Absolute path which is denoted with /root/desktop
23) #ls (This is list the content of a particular partition)
24) #ls –aldR
a (All hidden files which is starting from .file )
l (Long listing)
d (To show only you directories)
R (To see the content of subfolders)
#ls –ld /home/sameer (To see only directories)
#ls sh[]* (It will list all which is starting from the word sh and in which
third position can be letter or no which we can put in square
bracket [] after * defines anything)
[] This is known as positional parameter.
[]
# ls sh[123456789]*
# ls sh [09]*
# ls sh [02468]* even no match
# ls sh[!02468]*
! not operator
# ls –al | grep ^d (It shows only dir)
# ls –al | grep ^ (It shows only normal files)
Note : ^ this symbol is known as caret.
* , ? is known as wild characters in windows but unix it is known as
globbing characters or meta characters.
25) #mv oldfoldername newfoldername (To rename folder or filename)
26) #mv /root/sameer/cms /home/sameer (To move folder from one
location to another)
27) #rm filename (To delete a file)
28) #rmdir dirname (To delete an empty folder)
29) #rm –r foldername (To delete subdir of a particular folder with
interactive)
30) #rm –rf (To remove all forcefully all the content)
31) #touch newfile (It will allow you to create new empty file as well as
to even to update timestamp of a file)
32) #file filename (To recognize a file type)
33) #less filename (To view a file content only)
34) #more filename (To view a file content only)
35) #slocate filename or foldername (To find or search something on a
system)
36) #locate filename or foldername (To find or search something on a
system)
Note: slocate is actual command which is symlink to /usr/bin/locate
Note:
37) #man command (Help command of linux)
38) #info command (Help command of linux)
39) #command help (Help command of linux)
# whatis command (Help command of linux)
41) #history (To see current command history of a terminal which
get store in a file .bash_history under home directory)
Note : !! (To repeat last command)
!c (To repeat last command that starts with C)
!n (To repeat a command by it’s number in history
output)
!n (To repeat a command entered n command back)
41) <ctrl+r> command (To search a repeated command)
42) #find / name “find data” –print & (To search files or folders in a
system)
43) #find . name “find data” –print & (To search files or folders in a
system)
#find / name “find data” –print 2>> /dev/null (To search files or folders in
a system by normal users and to suppress a message of permission
denied we use 2>> )
43) #
44) #which <command> (It shows the full path of shell commands)
#which clear (e.g. of above description)
#whereis <command> (It shows the full path of a command along with
it’s man pages location)
45) #tr ‘az’ ‘AZ’ < /etc/passwd (It translate the output from lowercase to
uppercase)
# ls –C | tr ‘az’ ‘AZ’
46) # tee (It reads from standard input and write to standard output files)
# ls | tee logfile (This command will take output of who
command and it will redirect to logfile (file)
# ls | tee | sort –r > /root/logfile
# cat /etc/passwd | sort –r | tee sam
Note : sort –r = it shows the output in reverse order
Note : Modes of vi is as follows :
Command mode :
• cursor movement
• change, delete, yank, put, search
Insert mode :
• Type in new text
• Return to command mode with <Esc>
Ex mode:
• Configuring , exiting saving
• Search and replace
Entering into insert mode :
• a append after the cursor
• i insert before the cursor
• o open a line below
• A append to end of line
• I insert at beginning of line
• O open a line above
<esc> takes you from insert mode back to command mode
Undoing changes
• u undo most recent change
• U undo all changes to the current line since the cursor landed on the line
• <ctrlr> redo last “undone” change
Searching for text
• /text search downwards for “text” word
• ? text search upwards for “text” word
• n continue search in the same direction
• N continue search in the opposite direction
Saving and exiting : ex mode
Save changes Abandon changes
Exit :wq , or shift zz :q or :q!
Do no exit :w :e!
Forcing changes :
Save changes
Exit :wq!
Do not exit :w!
• 5dd delete five lines
• x delete a character
• r replace a character (or press insert twice to replace)
• R replace characterforcharacter until you press <esc>
Extra Options of vi:
Change, Delete, and Yank :
Change Delete Yank(copy)
Line cc dd Yy
Letter cl dl Yl
Word cw dw Yw
49) #vi –m filename (File is nonmodifiable)
50) #vi –R filename (File is only modifiable by using the exclamation
point :w!)
51) #vi –n filename (Do not use a swap file for a backup [useful for
floppies] )
52) #vi –r filename (Recover data from a swap file after a crash)
53) #vi –x filename (Encrypt file when saving, decrypt file when editing)
54) #vi + filename (It will open file and it will go to last line of the file)
: Backup Utilities:
55) #tar (tape archive)
#tar –cvf /root/backup.tar /projects /data /sameer (To create a tar file
Backup)
#tar –tvf /root/backup.tar (To view the content of a tar file)
# tar –xvf /root/backup.tar (To extract the tar file but before
extraction of a file you should be into
destination folder)
Note : Remember tar command never compress the data but it only
combines multiple data into one single tar file.
56) # compress –v /root/backup.tar (It compress tar file to ratio of approx.
50% 60%)
v = verbose
Note : After compressing a tar file it gives an extension to the file i.e.
backup.tar.Z
# zcat backup.tar.Z (It reads a contain of an *tar.Z file)
backup.tar.Z
# uncompress backup.tar.Z
# tar –Zcvf /root/backup.tar.Z /projects /data /sameer
(To create a tar file along with compress utility)
# tar –Ztvf /root/backup.tar.Z (To view the content of a compress tar
file)
#tar –Zxvf /root/backup.tar.Z
(To extract the compress tar file but before extraction of a file you should be
into destination folder)
# gzip v /root/backup.tar (It zips a tar file with an extension
.tar.gz)
.tar.gz
# gzip –lv /root/backup.tar.gz (To view the contents of an .tar.gz file)
.tar.gz
# gunzip –v /root/backup.tar.gz (To extract the .tar.gz file)
.tar.gz
# tar –zcvf /root/backup.tar.gz /projects /data /sameer
(To create a tar file along with zip utility)
# tar –ztvf /root/backup.tar.gz (To view the content of a zip tar
file)
# tar –zxvf /root/backup.tar.gz
(To extract a zip tar file but before extraction of a file you should be
into destination folder)
# bzip2 v /root/backup.tar (It zips a tar file with bzip2 utility an
extension .tar.bz2)
.tar.bz2
# bunzip2 –v /root/backup.tar.bz2 (To extract the .tar.bz2 file) .tar.bz2
# tar –jcvf /root/backup.tar.bz2 /projects /data /sameer
(To create a tar file along with bzip2 utility)
# tar –jtvf /root/backup.tar.bz2 (To view the contents of an .tar.bz2 file).tar.bz2
# tar –jxvf /root/backup.tar.bz2
(To extract a bzip2 tar file but before extraction of a file you should be
into destination folder)
# zip –v /root/file1 (To zip a file with having extension i.e .zip)
.zip)
# unzip –l /root/file1.zip (To view a zip file content)
#fileroller (It’s an graphical utility for all kind of tar or
zip,compress)
ln (Link command )
There two type of link can be made to a files or folder.
Symbolic link : is a file that points to another file. In between two
link file both the file separately represents different inodes no.
# ln –s <filename> <filename>
Hard link : One physical file on the filesystem each link
references the file’s inode. File is present in the file systems as long as
at least one link remains. After linked between two files both file
represent to one inode number.
# ln <filename> <filename>
57) # head /etc/passwd (To show you first top 10 lines (default) in a file)
# head –n 40 /etc/passwd (To Show you first top 40 lines)
58) # tail /etc/passwd (To show you last 10 lines (default) in a file)
# tail –n 20 /etc/passwd (To show you last 20 lines )
# tail –f /var /log/messages
(To show automatic updates made into this file)
# watch tail /var/log/messages
(To show automatic updates made into this file)
59) # wc /etc/passwd ( “Word Count” in a file or into some output)
# wc –l /etc/passwd ( To read how many lines are available in a file)
lines
# wc w /etc/passwd (To read how many words are available in a file)
words
# wc c /etc/passwd (To read how many characters are available in a
file)
# ls –al | wc –l
60) # sort /etc/passwd (Sort lines of a text files)
# sort r /etc/passwd (sort in a reverse order)
# sort n /etc/passwd (sort in a numeric order)
# tail /etc/passwd | sort (It will display last ten line with alphabetical
order)
61) # cut –d: f7 /etc/passwd | sort | uniq
(To cut the out put of a file –d: means delimeter or separator –f7 field no
7 of a file /etc/passwd)
62) # grep bash /etc/passwd (To search a bash word from a file)
# ls –R | grep .conf
Note : Global Regular Expression Print (grep)
# ls –R | grep .conf | wc –l
# ls –al | grep ^d ( To search for only directory)
# dmesg | grep CD
# dmesg | grep –i cd (To ignore case while searching a word)
# cat /etc/init.d/functions | grep \(\) | sort | nl
63) sed (stream editor which is use to replace a word with another word)
#sed ‘s/bash /nologin/g’ /etc/passwd | grep nologin
64)
:Linux File Systems:
A filesystem is a data structure written to the media that allows
users to store and access files. The default filesystem for Red Hat Linux is
the Third Extended Linux Filesystem or ext3. Red Hat Linux supports
over 20 different filesystem types.
: An Inode :
An inode table contains a list of all files in an ext2 or ext3 filesystem.
An inode (index nodes) is an entry in the table, containing information
about a file (the metadata), including:
• File type, permissions, link count, UID, GID
• The file’s size and various time stamps
• Pointers to the file’s data blocks on disk
• Other data about the file
• Ext2 and ext3 file systems keep a list of files in the file system in a
table called an inode table.
• An individual entry in the inode table is called an inode.
• The inode is referenced by it’s number, which is unique within a file
system.
An inode maintains the following thing :
The file type
File permission
Link count : the number of file names associated with the node number
The user ID number of the file owner
The group ID number of the associated group
Time stamps, including last access time, last modification time, and inode
change time
Location of the data on the hard disk
Other metadata about the file
Note : Above points cam be check by executing ls –al command which
ls –al
shows same thing in a sequence.
e.g. : ls ali
total 28
: The seven Fundamental File types :
• regular file
• d directory
• l symbolic link
• b block special file
• c character special file
• p named pipe
• s socket
: Filesystem Structure of Linux :
Interesting directories and their contents
Directory Description
/ The root directory where the file system begins. In most cases the root
directory only contains subdirectories.
/boot This is where the Linux kernel is kept. It is a file called vmlinuz.
/etc The /etc directory contains the configuration files for the system.
Most of the files in /etc are text files. Points of interest:
/etc/passwd
The passwd file contains the essential information for each
user. It is here that users are defined.
/etc/rc.d
This directory contains the scripts that get the system started.
/etc/sysconfig
Red Hat systems have this directory. It contains a lot of startup
scripts and configuration files for various services.
/bin, /usr/bin These two directories contain most of the programs for the system. The
/bin directory has the essential programs that the system requires to
operate, while /usr/bin contains applications for the system's users.
/sbin, /usr/sbin The sbin directories contain programs for system administration,
mostly for use by the superuser.
/usr The /usr directory contains a variety of things that support user
applications. Some highlights:
/usr/X11
The X Windows system
/usr/dict
Dictionaries for the spelling checker. Bet you didn't know that
Linux had a spelling checker.
/usr/doc
Various documentation files in a variety of formats.
/usr/man
The man pages are kept here.
/usr/src
Source code files. If you installed the kernel source code
package, you will find the entire Linux kernel source code here.
/usr/local /usr/local and its subdirectories are used for the installation of
software and other files for use on the local machine. What this really
means is that software that is not part of the official distribution (which
usually goes in /usr/bin) goes here.
When you find interesting programs to install on your system, they
should be installed in one of the /usr/local directories. Most often,
the directory of choice is /usr/local/bin. On Red Hat systems, the /
usr/local directories are created but they are empty, ready for your
use.
/var The /var directory contains files that change as the system is running.
This includes:
/var/log
Directory that contains log files. These are updated as the
system runs. You should view the files in this directory from
time to time, to monitor the health of your system.
/var/spool
This directory is used to hold files that are queued for some
process, such as mail messages and print jobs. When a user's
mail first arrives on the local system (assuming you have local
mail), the messages are first stored in /var/spool/mail
/lib The shared libraries (similar to DLLs in that other operating system)
are kept here.
/home /home is where users keep their personal work. In general, this is the
only place users are allowed to write files. This keeps things nice and
clean :)
/root This is the superuser's home directory.
/tmp /tmp is a directory in which programs can write their temporary files.
/dev The /dev directory is a special directory, since it does not really
contain files in the usual sense. Rather, it contains devices that are
available to the system. In Linux (like Unix), devices are treated like
files. You can read and write devices as though they were files. For
example /dev/fd0 is the first floppy disk drive, /dev/hda is the first
IDE hard drive. All the devices that the kernel understands are
represented here.
/proc The /proc directory is also special. This directory does not contain
files. In fact, this directory does not really exist at all. It is entirely
virtual. The /proc directory contains little peep holes into the kernel
itself. There are a group of numbered entries in this directory that
correspond to all the processes running on the system. In addition,
there are a number of named entries that permit access to the current
configuration of the system. Many of these entries can be viewed. Try
viewing /proc/cpuinfo. This entry will tell you what the kernel
thinks of your CPU.
/mnt Finally, we come to /mnt, a normal directory which is used in a special
way. The /mnt directory is used for mount points. As we learned in the,
the different physical storage devices (like hard disk drives) are
attached to the file system tree in various places. This process of
attaching a device to the tree is called mounting. For a device to be
available, it must first be mounted.
When your system boots, it reads a list of mounting instructions in the
file /etc/fstab, which describes which device is mounted at which
mount point in the directory tree. This takes care of the hard drives, but
you may also have devices that are considered temporary, such as CD
ROMs and floppy disks. Since these are removable, they do not stay
mounted all the time. The /mnt directory provides a convenient place
for mounting these temporary devices. In a normal installation, you
will see the directories /mnt/floppy and /mnt/cdrom. To see what
devices and mount points are used
55) #
56) df –h –T (Report disk space usage)
h displays sizes in easier to read units
T displays which file system is used by particular filesystem
h Human readable means in MB or KB or GB
57) du –h /data (Reports disk space usage used per directory)
: Formatting a Floppy :
Two types of format needed to prepare a floppy
A low level format (rarely needed)
• fdformat /dev/fd0F1440
A filesystem, one of
• mkfs t ext2 /dev/fd0
• mke2fs /dev/fd0
• mkfs t vfat /dev/fd0
• mformat a:
74) #alias cls= ‘clear’ (this is will create alias temp but if you want
permanent
then write in user’s home directory in .bashrc file to remain last even if
user logged out)
75) #su ( if a user name is not supplied, the su command assumes
that
you wish to become root.)
76) #su ( if a user name is not supplied, and if you type dash after
su
command then assumes that you wish to become root and
you want open a new shell after login.)
77) #su username ( to change identity or to switch identity)
78) #su username ( to change identity or to switch identity with available
with new shell after login)
79) #who (to find out who is logged in)
80) #users ( )
81) #w (
82) #groups (to find out what groups you belong to)
83) #id (to find out group id , user id)
84) #last ( who has logged in a system last ,or who has
rebooted
system last time)
85) #whoami (to find out who you are)
86) #umask ( to check default permission)
• umask value is set for normal users is 0002
• umask value is ser for root user is 0022
Without umask in effect the umask value for files it is
umask 666 and
666
for folders it is 777
Umask value can be set per individual user by setting umask in
each users home directory’s there is a file called as .bashrc ,
which will be read only once when users logged into system
If you want change umask value globally to all users so you have
set this value in
Umask value is calculated for root and normal users is
666 777
002 002
664 775
87) #newgrp othergroup (Where othergroup is one of the user’s secondary
groups)