Monday, August 29, 2011

Mastering in Red Hat Linux

Mastering in Red Hat Linux
Red Hat Certified Technician
Module I: RH033 Linux Basics

Unit – 1: Introduction
Unix History
Unix was created by Dennis Ritchie and Ken Thompson in the year 1969 in AT&T Bell
Laboratories. There are various distributions of Unix such as: AIX from IBM, XENIX from
Microsoft, Solaris from Sun Microsystems, IRIX from SGI and HP-UX from HP.
Unix Principle:
• Everything is a file, including a hardware. The Unix security model is based around the
security of files.
• Configuring data stored in text. Storing configuration in text makes moving the
configuration from one machine to another very easy.
• Small single purpose program. To perform complex task, these small purpose programs can
be chained.
GNU Project/ FSP
• GNU project was started in the year 1984. Its goal was to create free UNIX clone.
• By the year 1990, almost all the user required applications were developed.
• Free Software Foundation (FSF) manages GNU project. It is non-profit making organization.
• The softwares are distributed under General Public License ( GPL)
• GNU refers to GNU is Not Unix.
Linux Origin
• A Finnish college student named Linus Trovalds created a Linux Kernel in the year 1991.
• When Linux Kernel combined with GNU applications, a complete Unix-like operating system
became possible.
Red Hat Linux
• It distributes the latest version of Linux.
• It distributes the commonly used applications with its package.
• Established in 1995 by Bob Young and Mark Ewing.
• In 1996, Red Hat 4.0 Linux was named desktop operating system of the year.
• In 1997, Red Hat 5.0 Linux was named network operating system of the year.
• In 1998, Red Hat's market share increased from 6.8% to 17.2% out of total Unix based
operating system.
• In 1999, RHCE Certification was introduced.
• In 1999, Red Hat's market share increased upto 28% out of total Unix based operating
system.
• Since 2002, RHCE Certification stands as the best professional computer based certification.
Note: The Research was conducted by Info-World magazine.
Recommended Hardware Requirements (Red Hat Linux 9)
• Pentium III or higher
• 128 Mb RAM or higher
• 5 Gb Hard Disk partition or higher
• Bootable CD-ROM
• Floppy Disk Drive.
2
By Akhil Mathema
Unit – 2: Quick Tour
Run Levels
0 - halt
1 - single user
2 - multiuser
3 - multiuser
4 - unused
5 - GUI (Graphical User Interface) or X window
6 - reboot
Shutting down the system
$ halt
$ poweroff
$ init 0
$ shutdown -h now
Virtual Console
There are total 6 virtual consoles:
tty1 --> Alt+F1
tty2 --> Alt+F2
tty3 --> Alt+F3
tty4 --> Alt+F4
tty5 --> Alt+F5
tty6 --> Alt+F6
The seventh one is for the X window (GUI based) for that Ctrl+Alt+F7. And to return back to
virtual consoles from X window, user Ctrl+Alt+F1/2/3/4/5/6. X window system's terminals are
called pseudo terminals.
User Login
When logged as root (superuser) the prompt at console seems like:
[root@localhost root]#
When logged as local user the prompt at consosle seems like:
[localuser@localhost localuser]$
Adding User and assigning password
# useradd {name}
# passwd {name}
Type New-Unix Password: *******
Re-type New-Unix Password: *******
passwd: all authentication tokens updated successfully
Listing Files:
“ls” command displays files & subdirectories of the current directory.
Color code for file:
white - normal file
green - execute file
blue - directory
yellow - device file
cyan - link file
magenta - image file
3
By Akhil Mathema
Creating file
$ cat > {filename}
----
Ctrl+d (to save and exit)
$ cat {filename} (to view the file)
$ mkdir {directory name} (to make directory)
$ cd {directory name} (to change directory)
Unit – 3: File and Shell Basics
Running Commands:
syntax: command [option] [argument]
• each block is separated by a space
• option modifies the behavior of command
• argument may be filename or other information needed by command
Command “pwd” is used to print the current working directory.
Command “ls” displays the contents of current or specified directory.
Syntax: ls [option] [directory]
options:
-a lists all the contents of the specified directory including hidden, current
directory(.) and parent directory(..). Files/directories whose name begin with “.” are hidden
-A is same as of -a, except it doesn't display . & ..
-l displays the long list of the contents of the directory
Command “cd” is used to change directory. While changing directory to other subdirectories, full
path name is to be given.
$ cd /directory/subdirectory
note: here the first “/” stands for the root directory like “C:/” in Ms-dos.\
$ cd ---> only enables the user to reach user's home directory.
$ cd - ---> reaches to the previous directory
$ tree ---> displays files and directories in tree structure
File names
• filenames can be up to 256 characters long
• filename that begin with “.” are known as hidden files
• special characters need special handling
Checking free space
command “df” displays the free space for the file system
# df -h (disk free in human readable form)
command “du” displays the disk usage
# du -h /var/log (to view the disk usage of /var/log directory)
4
By Akhil Mathema
File Manipulation
command “mv” is used to move a file
syntax: mv [source filename] [destination filename]
• if the source filename and destination filename is same, the file will be renamed
• if the destination filename exists, the file will be overwritten
command “cp” is used to copy file from one location to another inside the same or different
directories.
command “touch” is used to create an empty file. But if the filename already exists, the access
time will be modified.
Command “rm” is used to delete a file
options:
-i ---> interactive mode, asks confirmation for the removal of file
-r ---> to remove a non-empty directory
-f ---> to remove file or directory forcibly without asking any confirmation
command “rmdir” is used to delete an empty directory
Running multiple commands on the same command line
syntax: first command ; second command
syntax: first command && second command
Here, “;” causes to run the second command only after the successful execution of the first
command while “&&” causes the commands to be executed sequentially independent of each
other.
Example:
$ mkdir dir1; cd dir1
Viewing text files
$ cat [option] filename
options
-s ---> squeeze [replaces the multiple blank lines by a single blank line]
-n ---> displays the line number
-A ---> displays all including control and non-printable characters like spaces, return, etc
Command “less” displays the contents of a file, one screen at a time either forward or backward.
Syntax: less {filename}
d ---> moves half screen forward
d ---> moves half screen backward
spacebar ---> moves forward by one screen
enter/return ---> moves ahead by a line
note: the above options are not command line options
options:
-s ---> squeeze [replaces the multiple blank lines by a single blank line]
-c ---> clear the screen before displaying the file
There are also other commands like “more”, “pico”, “joe”, etc to view files.
5
By Akhil Mathema
Viewing first and last few lines of a file
Command “head” displays first few lines of a file which is 10 lines by default.
Command “tail” displays last few lines of a file which is 10 lines by default.
Example:
$ head -n 5 /etc/passwd ---> displays first 5 lines of /etc/passwd file
$ tail -f /var/log/messages ---> it is used to view constantly growing (updating) log file
File Globbing
It helps to replace the same pattern on multiple filenames. In MS-DOS it is known
as wild cards, whereas in Linux, it is known as metacharacters
? ---> matches any single character
• ---> matches any number of character
• [a-z] ---> matches into the range
• [^a-z] ---> matches all except the range
Example:
$ rm a??? ---> deletes all files of 4 characters starting with “a”
$ rm a* ---> deletes all files preceeding with “a”
$ rm [a-c] ---> deletes all files proceeding from “a” to “c”
$ rm *.* ---> deletes all files with “.” extension but not directory
Home Directory
Tild i.e. “~” represents home directory
$ ~ --->displays the path of the current user's home directory
$ dirs
~$
touch ~user/file1 ---> makes a blank file file1 on user's home directory