SlideShare a Scribd company logo
UNIT-1
Idea and History of Linux
First Linux version (UNIX) operating system developed by “Ken Thompson” and “Dennis Ritchie in
“AT &T Bells Lab U.S.A” in 1970 work on CUI mode.
1984 GNU project was introduced (Graphical Not UNIX) it was an organization the aim of this
organization to develop the clone of UNIX Operating System.
1987 Minix Kernel was introduce.
Linux Origin: -
 Linus Torvalds created its KERNEL in 1991.
 with assistance from programmers around the world
 first posted on Internet in 1991
 Linux 1.0 in 1994; 2.2 in 1999
 Today used on 7-10 million computers
 with 1000’s of programmers working to enhance it
What is Linux ?
 A fully-networked 32/64-Bit Unix-like Operating System
 Unix Tools Like sed, awk, and grep (explained later)
 Compilers Like C, C++, Fortran, Smalltalk, Ada
 Network Tools Like telnet, ftp, ping, traceroute
 Multi-user, Multitasking, Multiprocessor
 Has the X Windows GUI
 Coexists with other Operating Systems
 Runs on multiple platforms
 Includes the Source Code
Red Hat Enterprise Linux
 Commercial Distribution
 Enterprise-targeted operating system
 Focused on mature open source technology
 12-18 month release cycle
 Versions available started from 2.1, 3.0, 4.0 now 8.x
 Support available up to 24 x 7 coverage plans
 Supports many processor architectures
Intel x86-compatible, Intel Itanium 2, AMD64, IBM PowerPC on eserver iSeries and eServer
pSeries and IBM Mainframe on eServer zSeries and S/390
The Fedora Project
 Red Hat-sponsored open source project
 Focused on latest open source technology
 Rapid four to six month release cycle
 Available as free download from the internet
 An open, community-supported proving ground for technologies which may be used in
upcoming enterprise products
 Red Hat does not provide formal support for Fedora Project
What is Kernel?
The kernel is the heart of the whole operating system. It manages communication with hardware,
decides which processes to run, and provides each process with an isolated, virtual address space in
which to run. The kernel is what your boot loader, GRUB , loads into memory. The kernel loads device
driver modules
What is "the shell"?
The shell is a program that takes your commands from the keyboard and gives them to the operating
system to perform. In the old days, it was the only user interface available on a Unix computer.
Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs)
such as the shell.
What is Boot loader ?
boot loader is the first software program that runs when a computer starts. It is responsible for loading
and transferring control to the operating system kernel software. The kernel, in turn, initializes the rest
of the operating system
GRUB (GRand Unified Bootloader), which is installed by default, is a very powerful boot loader.
GRUB can load a variety of free operating systems, as well as proprietary operating systems with chain-
loading (the mechanism for loading unsupported operating systems, such as DOS or Windows, by
loading another boot loader).
What is SWAP Partition ?
swap partitions are used to support virtual memory. In other words, data is written to a swap partition
when there is not enough RAM to store the data your system is processing.
Size of SWAP ?
 At least 256 MB
 Twice the amount of RAM on your machine
 Swap should equal 2x physical RAM for up to 2 GB of physical RAM, and then 1x physical
RAM for any amount above 2 GB, but never less than 32 MB.
 SWAP can also used after the installation
 Red Hat Enterprise Linux supports up to 32 swap files
Sample Partition Structure
Mount Point Size
/boot 128 MB
/ 2048 MB
/usr 2048 MB
/var 512 MB
/home 512 MB
SWAP Use recommended size
Similarity Between Linux & Windows
 Both are operating system.
 Multi-users.
 Multi-tasking & processing.
 Works in CUI & GUI mode.
Dissimilarity Between Linux & Windows
Linux Windows
1. Economical to use 1. Not Economical to use
2. More Security 2. Less Security
3. Mostly work in CUI 3. Mostly Work in GUI
4. Workstation & Server 4. Client & Server
Multi-tasking:- Multiple task can run process one by one at a time.
Multi-processing:- Multiple Programs can perform at a time
Principle of Linux
1. Everything is a file:- The UNIX security module is based around the security of files by
treating everything is a file. You can secure access to Hardware in the same way as you secure
access to document.
2. Small, Single purpose program:- UNIX provide many small utility that performs one task
very well.
3. Ability to chain programs together to perform complex task:- A core design feature of
UNIX is that the output of one programs can be input for another.
4. Configuration data stored in text:- all the data is stored in text b’coz text is
Universal interface and many UNIX utility exist to manipulate text. Storing
Configuration in text allows an administrator to move a Configuration from one
Machine to another easily.
Open Source Software
 When programmers on the Internet can read, redistribute, and modify the source for a piece of
software, it evolves
 People improve it, people adapt it, people fix bugs. And this can happen at a speed that,
compared to conventional software development, seems astonishing
Open source software refer to the software in which the source code is freely available to all
users to modify their Linux as their need.
Website
http://www.opensource.org/docs/defination.php
What is WINDOWS?
W- Wide
I- Interactive
N- Network
D- Development
O- Office
W- Work
S- Solutions
Distributors of Linux
1. Red hat Supported by RHEL
2. Suse Supported by NOVELL
3. Turbo Linux Supported by US & Japenese
4. Fedora Linux Supported by RED HAT
5. Sol Supported by Server Optimized Linux
End of UNIT-1
UNIT- 2
Linux Usage Basic
Login in to a Linux System:- Red Hat Linux provide two type of login method.
 Two type of login Screen :- Virtual Console [text based] and Graphical Login [display
manager]
 Login using login name and password.
 Each user has a home directory for personal file storage.
 Red Hat provides by default six virtual consoles that are [ctrl+alt+f1] to [ctrl+alt+f6].
 [ctrl+alt+f7] is used for Graphical mode.
 Init 6 and reboot command is used to restart.

Elements of ‘X’ Windows System:-
 The ‘X’ Windows system is Linux’s Graphical subsystem
 “X” Org. is particular version of the X windows system used by Red Hat.
 Look & Behavior Largely Controlled by the Desktop Envirment.
 Two Desktop environments provided by Red Hat. ---1. GNOME the default
Simple view of GNOME Desktop
 desktop environment. 2. KDE an alternate desktop envoirment.
Simple view of KDE Desktop
 Start “X” switch text base to graphical.
Following commands are used to create a new file
 NANO Easy, Editor, Simple
 VI Easy, Editor, Simple
 VIM Advanced featured with Encryption
 GVIM
Basic File editing – vi editor
 vi - the basic text editor
 three modes
● Command mode <= default startup
● Insert mode
● ex mode
 vi test <= a typical example
● Enter insert mode <i> and <CR>
● Enter <ESC> return to command mode
● Navigate the cursor
● h move cursor left
● j moves cursor down
● k moves cursor up
● l moves cursor right
Some Simple Commands
 ls = list the files and directory
 date = display date and time
 cal = display calendar
 clear = clear the screen
 pwd = prints the name of current working directory
 mkdir = creates the directory
 rmdir = removes the directory
 cd = changes the directory
 cat = display the contents of file
 rm = removes the files
 cp = copy the files and directory
 mv = move and rename ( files and directories )
 touch = updates the file/directory time-stamps
 less = pager command
 more = pager command
Commands
 G = go to last line in file
 1G = go to first line in file
 H = go to first line on screen
 M = go to middle line on screen
 L = go to last line on screen
 z<Enter> = make current line first line on screen
 z- = make current line last line on screen
 !!date = Inserts the current date and time in to file
 !}sort = Sorts the data of your file
 !}fmt -66 = formats the data of your file in to 66 column width
Ex mode : Search and Replace command
:%s/big/small
:%s/big/small/g
To display the list of files & Directories we use “ls” command.
Blue Color “Directories” and White Color files.
# it shows that login with Privilege User
$ it shows that login with Non- Privilege user
History command is used to show the past command.
Reboot, init 6, command is used to restart the system.
Power off Command is used to shutdown the system. If you want your system shut down after your
particular time like after 2 minute then command is
] # shutdown –h 2 [ -h for halt, 2 for 2 minute]
Creating directory:- ] # mkdir dir name
Entering into dir:- ] # cd dir name
Listing directory content:-
 Ls to show the list of files & directory
 Ls –a include hidden files
 Ls –l display extra information
 Ls –r recurse through directories
 Ls –ld directories and symlink information
Creating a user: - ] # Useradd username
] # passwd username
1. mkdir to create a directory (# mkdir dirname)
2. cd to change the directory (# cd dirname)
3. cd .. to come out from previous directory (# cd ..)
4. cd – to go at previous working directory (# cd -)
5. cd to go at the Home (~) directory (# cd)
6. pwd to display present working directory (# pwd)
7. rm to remove the file ( # rm -{option} file name.
Options are –i interactive
-r recurse
-f forcefully
8. rmdir to remove empty directory (# rmdir dirname)
9. rmdir –r dirname to remove any file & directory are exists.
The location of a file and directory can be specified by two methods
Absolute Relative
1. Begin with a forward slash 1. Do not begin with slash
2. Complete “road map” to file location 2. Specify location relative to your
Current working directory.
3. Can be used any time you wish to specify 3.Can be used as a stored way to
a file name. specify a file name.
End of UNIT-2
Unit-4
Browsing the file system
We have already discussed or learned in UNIX all, information treated as a file. Single disk can store
thousands of files or organizing the data on the disk the o/s provides a file system. There are three types
of file.
1. Ordinary & Regular file:- all files are created by a user come under these categories.
2. Directory file:- for each directory there is file by the same name as the directory. Which contain
information about files under that directory?
3. Device file:- device file are special types typically associated with input/output device such as
Printer, Tap Drive, HDD, FDD, CD-Drive.
Structure of the file system
Linux file system has a tree structure or hierarchical structure that is file & sub directories can be stored
in the directory.
~] # you are work in home directory.
/] # you are work in root directory.
1. /bin:- this is the binary directory. Which contain the executable files? When a program is
installed its binary files are stored here.
2. /dev:- dev stand for device that contains files that point to the hardware that make up the system.
3. /etc:- this folder contains various configuration files that can be manually edited to affect the
system charge.
4. /lib:- lib means “Library” files frequently used system files needed by program or the operating
system are stored here just like library files stored in “C:windowssystem” in windows o/s.
5. /usr:- Non-critical files are stored in this directory which contain a copy of most of the
directories in the root.
6. /var:- the various folder contains just that various files such as log file.
7. /tmp:- this is the directory that used by application for storing temporary files.
8. /opt:- the option directory stored add on component such as desktop envoirment database .
9. /mnt:- all storage media other than Linux partition are mounted here.
10. /root:- this is the home directory of the root user
11. /boot:- the boot loader files are stored here.
12. /home:- this is the directory that contain user’s file.
13. The /proc/ Directory - contains special files that either extract information from or send
information to the kernel. Examples include system memory, cpu information, hardware
configuration etc.
14. The /sbin/ Directory - stores executables used by the root user. The executables in /sbin/ are
used at boot time, for system administration and to perform system recovery operations.
Copying files and Directories
 If the destination is a directory, the copy is placed there
 If the destination is a file, the copy is overwrites the destination.
 If the destination does not exist, the copy renamed.
Command – cp source add destination add
Command – cp –[option] filename /dirname
-I = ask me before overwriting a file.
-r = recursively copy an entire directory tree.
-p = permission, ownership, & time stamps.
Move and renaming files & directory
Move command is used to move a file or directory from source to destination.
OR
Move command is used to rename a file or directory
Note: - if the destination is not reachable then it renames the file or directory.
Command: - mv [option] filename destination
For example: - create two directory named aa, bb.
~] # mkdir aa bb
~] # cd aa
aa] # nano hcl
aa] # mv hcl /root/bb
aa] # cd
~] # cd bb
bb] # ll
Now your file hcl has moved from aa to bb.
Nautilus:- graphical file system browser.
End of UNIT-4
Unit-5
User, Group, and Permission
What is User Account ?
 When a computer is used by many people it is usually necessary to differentiate between the
users, for example, so that their private files can be kept private. This is important even if the
computer can only be used by a single person at a time, as with most computers. Thus, each user
is given a unique username, and that name is used to log in.
User:-
 Every user is assigned a unique user ID no. (UID). (UID0) identify root.
 User’s name and UID are stored in /etc/passwd.
 User and assigned a home directory and a program that is run when they log in casually a shell.
 User can not read, write or execute each other, files without permission.
 Note to see UID run the ~] # Cat /etc/passwd.
What is Group ?
 Is a collection of users which make easy for administrators to perform the task of administration
level when they need to apply permissions and restrictions with same level to many of the users,
then such permission and restrictions can be applied to related group.
Group:-
 User’s are assigned to a group.
 Each group is assigned a unique group ID no. (GID).
 GID is stored in /etc/group.
 Each user is given their own private group. Can be added to other groups for additional access.
 All users in a group can share a file that belongs to the group.
 Note to see GID run the ~] # Cat /etc/group
The “root” user
 The root user: a special administrative account
● Same like “Administrator” we called in Win*
● Sometimes called the “superuser”
● root has complete control over the system
● An unlimited capacity to damage the system!
What is Permission ?
 Specifies what rights are you granting to users to access the resources are available in the
computer, so that important resources such as files are protected from unauthorized users.
Permission Types
Permissions- Symbolic Method
Four symbols are used when displaying permission.
 R: - permission to read a file or list a directories content.
 W: - permission to write a file or create and remove files from a directory.
 X: - permission to execute a program or change into a directory and do a long listing of the
directory.
 -: - no permission in place of the r, w, x.
Permissions- Numeric Method
 Four numbers are used when displaying or applying permissions
● 4 Permission to read a file or list a directory’s contents
● 2 Permission to write to a file or create and remove files from a
directory
● 1 Permission to execute a program or change into a directory and
do a long listing of the directory
● 0 no permission ( in place of the 4, 2, or 1 )
Examining Permission
 File permission may be viewed using ~] $ ls –l /bin/login -rwxr-xr-xl
root root 19080 Apr 1 18:26 /bin/login
 File type and permissions are represented by a 10 character string.
Changing File Ownership
 Only root can change a file’s owner.
 Only root or the owner can change a file’s group.
 Owner ship is changed with chown.
 ~] # chown username file/dirname
 Group ownership is changed with chgrp
 ~] # chgrp groupname file/dirname.
 To change access mode with chmod
 ~] # chmod mode file
 Where mode is
1. U, G, or O for User, Group, or Other
2. + sign for grant the permission.
3. – sign for deny the permission.
4. r, w, x, for Read, Write, Execute.
For Example:-
~] # chmod u=rwx, g=rw, o=r file name
~] # chmod ugo +r file name (for read permission to all).
~] # chmod a= rwx filename
Changing permission with numeric method
 Uses a tree digit mode number.
1. First digit specifies owner’s permission.
2. Second digit specifies group’s permission.
3. Third digit specifies other’s permission.
Applying Permission with Numeric Method
1. 4 (for read)
2. 2 (for write)
3. 1 (for execute)
Example: - ~] # chmod 640 file name
 If u wants to give the read, write, permission to owner then combined the both digit
code (4+2=6), and read permission to group (4), and for other’s on permission then (0). chmod
command is used to change access modes
 Numeric Method
● chmod 664 somefile  file name
(Grants Read and Write access to owner and group but read only it to and other. )
● chmod 600 somefile  file name
( Sets read and write permission to owner, with execute turned off, with others and group have
no permissions )
● chmod 444 somefile  file name
( Make the file world-readable )
Changing Permission Nautilus
 Nautilus can be used to set the permission and group membership of files and dir.
1. sIn a nautilus window right click on a file.
2. Select properties from the content menu.
3. Select the permission tab.
Note: - To check the permission use ls –l.
If we change the permission of any file and dir then their colors become green.
To add a user in a group
~] # usermod –G groupname username
To change the ownership of a user to other user:-
Log in with root’s home directory
~] # cd /home
Home] # chown username username
End of UNIT-5
Unit-6
Using the bash shell
What is shell script ?
 Shell scripts are text files that contains a series of commands or statements to be executed
 Shell scripts are useful for
 Automating commonly used commands
 Performing system administration and troubleshooting
 Creating simple applications
 Manipulation of text or files.
Shell makes an interface between Users & Kernel. There are three main shells for UNIX is: -
1. Bourn Shell
2. C Shell
3. Korn Shell
Now a days Bash shell become popular in Linux O/S. Broun again shell (Bash shell)
was released Brain fox & chief Remey as part of the free software foundation. The GNU project
features of Bash shell are: -
1. Input and output redirection.
2. Use of wild card.
3. Command line editing.
4. Zilde representation
5. Built- in shell command & Variables.
6. Command history and aliasing.
Command line Shortcuts
1. (*) Match zero or more characters.
2. (?) Match any single.
3. (0-9) Match a range of number.
4. (abc) Match any of the character in the list.
5. (^abc) Match all character in the list.
Notes: -
Remove all files in extension .mp3 we use.
Syntax: - ~] # rm *mp3
Remove all files in extension .txt we use.
Syntax: - ~] # rm *txt
To show the file which have second character with ‘O’ alphabate?
Syntax: - ~] # echo ?O*
To show the file which have Third character with ‘M’ alphabate?
Syntax: - ~] # echo ??m*
~] # ls a press tab key two times.
~] # cat a press tab key two times.
(This command is used to show the file & directories start with letter ‘a’ as like ajay.txt)
! char repeat last command that start with character.
Syntax: - ~] # ! char
Example: - ~] # ! d (any character alphabate)
! num repeat last command by this no. in history output.
Syntax: - ~] # ! num
Example: - ~] # !5
~] # mkdir –P work/{inbox,outbox,pending}/{normal,urgent,important}
Work
Inbox Outbox Pending
Normal Urgent Imp Normal Urgent Imp Normal Urgent Imp
To Check This: -
~] # ls
Then it shows (work directory)
~] # cd work
Work] # ls
Then it shows (inbox, outbox, pending directory)
~] # cd inbox
Inbox] # ls
Then it shows (normal, urgent, important sub directory)
Command Editing Trick
~] # ctrl –a moves to beginning of line.
~] # ctrl –e moves to end of line.
~] # ctrl –u delete to end beginning of line.
~] # ctrl –k delete to end of line when the cursor in the beginning of line.
~] # ctrl –arrow moves left or right by word.
GNOME Terminal
Application ---- Accessories ---- Terminal
Graphical terminal emulator that supply multiple “tabbed” shells.
 Ctrl + Shift + T create a new tab.
 Ctrl + Pgup/Pgdn Switch to next/previous
 Ctrl + Shift + W close the tab.
 Ctrl + Shift + C copies selected text.
 Ctrl + Shift + V paste text to the prompt
Creating Shell Scripts:-
Step 1:- use such as ‘VI’ to create a text file containing commands.
First line contain the magic shebang sequence: # !
Like # !/bin/bash
Comment your scripts !
Comments start with #
Make a Script
Open a new file with ‘VI’ editor like ~] # vi filename and type the following
~] # vi filename
Press “I” for insert mode.
# !/bin/bash
# this script display
Echo “the date & time are $ (date)”
Echo “your working directory is $ (pwd)”
Echo “your files & Dir. Are $ (ls -a)
Echo “your virtual consoles open are $ (who)
Press “ESC” key
:wq
To run the file ~] # ./filename
Step 2:- Make the script executable
~] # chmod u+x filename
To execute the new script:
1. Place the script file in a directory in a executable path
2. Specifying the absolute or relative path to the script on the command line.
Writing Programs using bash scripting
Sample Program 1
 # Simple Program for users input
 echo -n "Enter Your Name :"
 read a
 echo -n "Enter Your Age :"
 read b
 echo "Hello Dear $a your age is $b Years"
Sample Program 2
 # Addition of A and B number
 echo -n "Enter First number :"
 read a
 echo -n "Enter Second number :"
 read b
 c=`expr $a + $b`
 echo "Result is" $c
Sample Program 3
 # Multiply A and B
 echo -n "Enter First number :"
 read a
 echo -n "Enter Second number :"
 read b
 c=`expr $a * $b`
 echo "Result is" $c
Sample Program 4
 # Divides A from B
 echo -n "Enter First number :"
 read a
 echo -n "Enter Second number :"
 read b
 c=`expr $a / $b`
 echo "Result is" $c
Sample Program 5
 # Subtract B from A
 echo -n "Enter First number :"
 read a
 echo -n "Enter Second number :"
 read b
 c=`expr $a - $b`
 echo "Result is" $c
Sample Program 6
 # To Check Bigger number between two numbers
 echo -n "Enter First number :"
 read a
 echo -n "Enter Second number :"
 read b
 if [ $a -gt $b ]; then
 echo "A is BIG"
 elif [ $a -eq $b ]; then
 echo "Both are equal"
 else
 echo "B is BIG"
 fi
Sample Program 7
 # To show table of number given by user
 i=1
 echo -n "Enter any number : "
 read n
 while [ $i -le 10 ]
 do
 echo "$n X $i = `expr $i * $n`"
 i=`expr $i + 1`
 done
Sample Program 8
 #Checks to see hosts 192.168.0.1 to 192.168.0.10 are alive
 for n in {1..10}; do
 host=192.168.0.$n
 ping -c2 $host &> /dev/null
 if [ $? = 0 ]; then
 # print host names 30 char wide and left justified
 printf "%-30s is aliven" $host
 else
 printf "%-30s is NOT aliven" $host
 fi
 done
UNIT-7
Standard Input / Output and Pipes
One of the most important features of Linux (and UNIX) is the ability to redirect a command’s input,
output, and error data. Linux provides the three I/O channel to programs.
1. Standard Input Keyboard by default
2. Standard Output Terminal Windows by default
3. Standard error Terminal Windows by default
Redirecting to file
1. > Redirect STD OUTPUT to file
2. 2> Redirect STD ERROR to file
3. &> Redirect all output to a file
Common Redirection operators
1. Command >filename Direct standard output command to file.
2. Command >>filename Append standard output command to file.
3. Command <filename Send file as input to command
4. Command 2>filename Redirected error message from command to file.
5. Command 2>>filename Append error message from command to file.
1. Input Redirection:- any text input enter from the keyboard redirect in to specified file. ~] # cat
>filename, ~] # ls –l>filename
2. Output Redirection:- instruct to shell to redirect to a command output into the specified file
instead of the terminal. ~] # cat <filename
3. Error Redirection:- ~] # xyz 2>error message
Experiment of upper command by the following process
First of create a user on root and login to that user and follow the step
1. ~] # find / -name passwd
2. ~] # find /etc –name passwd
3. ~] # Find /etc –name passwd >raj (filename) {send the result in raj and show remaining error}.
4. ~] # cat raj (filename) {raj show the result}.
5. ~] # find /etc –name passwd >>raj (filename) {add the result in raj which comes in command
number 3}.
6. ~] # cat raj {show the total result in raj}
7. ~] # cat <raj {command 6 and 7 has same output we use command as well as command 7}.
8. ~] # find /etc –name passwd 2>raj2 (filename) {send the errors in raj2(filename) and show
result}.
9. ~] # cat raj2 (filename) or ~] # cat <raj2 (filename) {to see the error are in raj2 (filename)}.
10. ~] # find /etc –name passwd 2>>raj2 (filename) {add the error which are comes in command 8}.
11. ~] # cat raj2 (filename) or ~] # cat <raj2 (filename).
12. ~] # find /etc –name passwd &>raj3 (filename).
13. ~] # cat raj3 (filename).
14. ~] # find /etc –name passwd >aa >bb {to send all the result in file named aa and error in file
named bb}.
15. ~] # cat aa {to see result}.
16. ~] # cat bb {to see error}.
Redirecting STDOUT to a Program (Piping)
 Pipes (the | character) can connect commands. (command1 | command2)
 Sends STDOUT of command1 to STDIN of command2 instead of the screen.
 STDERR is not forwarded across pipes.
 PIPE is used to add two or more commands. Ex ~] # ls –l | more
 Tr translate the upper case into lower case and lower case into upper case. Original file
will be unchanged.
 Syntax:- ~] # tr ‘a-z’ ‘A-Z’ <filename
Syntax:- ~] # tr ‘A-Z’ ‘a-z’ <filename
Redirecting STDOUT to a Program Examples
 Less: view input one page at a time. ~] #
ls –l /etc |less {input can be searched with /}.
 Lpr: Send input to a printer.
~] # echo “test print” | lpr or ~] # echo
“test print” | lpr –p printer_name.
 Mail: Send input via e-mail.
~] # echo “test mail” | mail-s “test” user@example.com
Scripting for loops
Performing actions on each member of a set of values.
Syntax: make a file with VI editor
#!/bin/bash
# alive2.sh
# checks to see if hosts 192.168.1.1-192.168.1.20 are alive
# iterate through IP addresses
For n in {1…20}; do
Host=192.168.1.$n
Ping –c2 $host &> /dev/null
If [$? =0]; then
Echo “$host is up”
Else
Echo “$host is down”
Fi
Done
Press ‘ESC’ key
: Wq
~] # chmod u+x raj (filename).
~] #. /raj (filename).
Filter Command
~] # grep. /etc/passwd {it show the content of file after filtering}.
Sort Command
~] # sort color (it show the alphabetical content).
~] # ls –l |sort
Mutt Command (this command is a text-based mail client).
UNIT-8
Test Processing Tools
Introduction to String Processing
Head and Tail
 Head shows the first 10 lines of a file
● Try head /etc/somefile
● Try head -n 5 /etc/somefile (shows the first 5 lines of the file)
 Tail shows the last 10 lines of a file
● Try tail /etc/somefile
● Try tail -n 5 /etc/somefile (shows the last 5 lines of the file)
wc, sort, uniq , cut and paste
 wc “Word Count” used to count the line, word, character in the file.
 Syntax ~] # wc -l filename (for count the line)
~] # wc -w filename (for word count)
~] # wc -c filename (for column count)
~] # wc -m filename (for the character count)
● Options ( -l (for line), -w(for word), -c(for column) )
 sort “Sorting Order” it is used to sort the data into ascending or descending order but original
file will be no change.
 Syntax:- ~] # sort –r filename {for descending sort}
● ~] # sort filename {for ascending}
● ~] # sort –n filename {for ascending numeric sort
● ~] # sort –nr filename {reverse numeric sort}
● ~] # sort –u filename {unique sorting}
● sort OPTIONS somefile
● Options ( -r, -n )
 uniq “Removes duplicate lines in a file”
● -u to show only truly uniq
● -d to show lines that are repeated in the input
● -c to count lines
 cut “ Display specific columns of the file data
 Syntax~] # cut -c2-5 filename
~] # cut –f3 –d: /etc/passwd
 paste “Paste files together”
~] # paste file1.txt file2.txt > file3
aspell, expand look and sed
 aspell “To check spelling in file “
 Syntax ~] # aspell check filename
 expand “Expand tabs into spaces”
● expand tabfile.txt > result.txt
 Look give the matches related work from directories.
 Syntax~] # look word
 Sed (stream editor) use to search and replace pattern but original file will be unchanged.
 Syntax~] # sed ‘s/Ajeet/amit’ filename
~] # sed ‘s/Ajeet/amit’ filename >new filename (saving changes in
another file).
String Processing with Regular Expressions
Grep, sed, awk, diff
 grep This command is used to search a word in a file.
 Syntax ~] # grep ‘[Cc]at filename
~] # grep -i ‘[f]rog filename (i- represents case –insenstivity)
 Syntax ~] # grep -A3 ‘cat’ filename (A stand for after)
~] # grep -B3 ‘cat’ filename (B stand for befor)
“ Prints lines of files where a pattern is matched
● grep amit /etc/passwd
 sed “ Stream Editor :- Reads a file ; writes out the data performe search and replace “
original will be unchanged.
● sed ‘s/big/small/’ somefile
● sed ‘s/big/small/g’ somefile
 awk “ Programming language for editing text “
● awk ‘ /bash/ { print } ‘ /etc/passwd
 diff this command is used to make a difference between 2 files.
Syntax~] # diff file1 file2
UNIT-9
VIM: An Advanced Text Editor
Vim stand for (visual improved editor):- it is a advance version of VI editor it create the text file
in encrypted form.
Syntax:- vim -x filename
Introduction of VIM:-
 Newer version of VI the standard UNIX text editor.
1. Executing VI runs VIM by default.
 GVIM- graphical version of VIM.
1. Application + Programming VI
2. Providing by VIM –x 11 Package
Advantage of VIM:
 Speed: do more with fewer keystrokes.
 Simplicity: no dependence on mouse/GUI
 Availability: included with most UNIX like uses.
Disadvantage of VIM:
 Difficulty: steeper learning curve than simpler editors.
 Keystroke behavior is dependent upon VIM’s mode
In this VIM or VI editor you have three mode.
1. Command mode: (Default) move cursor, cut, text, change mode.
2. Insert mode: modified text.
3. Ex-mode: save & quit etc.
Moving Around command mode:
 Move by word w, b
 Move by sentence ), (
 Move by Paragraph }, {
 Jump by line X XG
 Jump by end line G
Shortcut of Command mode:
 A it stand for append to the end line.
 I insert at beginning of the line.
 o insert a new line down side.
 O insert a new line up side.
 U used for undo
 For mouse: h-left, j-down, k-up, l-right.
Command for word replacement:
~] # :%s/old word/new word
Manipulating Text Command mode
Word Change (Replace) Delete (Cut) Yank (Copy)
Line CC dd yy
Letter cl dl yl
Word cw dw yw
Sentence ahead c) d) y)
Sentence behind c( d( y(
Paragraph above c{ d{ y{
Paragraph behind c} d} y}
Line wise Paste
 p used for paste below the line
 P used for paste above the line
Character wise & word wise
 p used for paste after the cursor
 P used for paste before the cursor
UNIT-10
Basic System Configuration Tools
IPAddressing
 Is a 32bit Logical Address which make computer to communicate to each others using TCP/IP
protocol.
 Defined in different classes From A to E
 Class A= 1 to 126
 Class B = 128 to 191
 Class C = 192 to 223
We can assign IPAddress to computer by using two methods
1. Static [ Manually ]
2. Dynamic [ Using DHCP Server ]
Network Configuration Commands
 ifconfig
 Used to view the properties of active and inactive network interfaces
 ifconfig
 Ifconfig –a = to display information about inactive network interface
 ifup / ifdown
 Used to activating and deactivating a network interface
 ifdown eth0
 ifup eth0
 mii-tool
 Tool allows a system administrator to view, monitor, log and change the negotiated speed of
Ethernet network cards
 mii-tool –v = to view the current status of network interface card
 mii-tool –v --force 100baseTx-FD eth0
 To change the negotiated speed of Ethernet network card
Network Configuration Utilities
 neat / neat-tui
 Text-based network configuration tool
 Only writes config files. Does not activate device or changes.
Use ifup/ifdown to active changes or restart the network service
 Used by kudzu when new network card found at boot time
 system-config-network
 GNOME-based network configuration tool
 Can be launched by a non-privileged user, but requires authentication as root.
Printing in Linux
 Printer may be local or networked.
 Print requests are sending to queues.
 Queued jobs are sent to the printer on a first come first serve basis.
 Jobs may be cancelled before or during the printing.
 Lpr command is used to print the file.
System-config-printer
UNIT-11
Investing and Managing Processes
What is a Process?
 A process in an executing program with several components and properties.
 A process is a shell command or a program in execution.
 When you log in, a process is created. This process is executing the shell
 When you execute a shell command, a new process is created. When the command terminates,
the new process dies.
 A single user can have many processes executing at the same time
ps command
 The command ps is used to determine the status of active processes. The command returns the
process id (PID) number and other information such as the amount of CPU time the process has
used (TIME) and the command which invoked the process (CMD).
 Options may be combined.
top command
 The command top is used to show a real-time view of Linux tasks
 top can be used to display the CPU/memory usage of each task
 top
Terminate Processes
 kill is used to terminate processes or to send signal to processes.
 Examples:
● kill PID
● Terminate the process with the process id (PID).
UNIT-12
Configuring the Bash Shell
What is Bash Shell? It is the default shell for Linux operating system it was introduced in 1975.
Aliases:-
 Aliases let you create shortcuts to commands.
 Use alias by it self to see all set aliases.
 Use alias followed by an alias name to see alias value.
UNIT-13
Finding and Processing Files
Locate:-
 Queries a pre-built database of paths of files on the system.
2. Database must be updated by administrator.
3. Full path is searched, not just file name.
 May only search directories where the user has read and execute permission.
Note:- Locate command is used to search the full path of file, and display if locate command does
not run then firstly run ‘updatedb’ command at root login after that run “Locate” command.
Syntax:- ~] # locate dirname
slocate and find
 slocate “ Search for files “
● slocate somefile
 find “ Search for files “
● find /home –name somefile
● find /home –iname somefile [ case-insensitive search ]
● find /home –user amit –group amit somefile
● find /home –perm 755
● find /home –size 1000kb
● find /home –user username
● find /home –user username –o –user username
Find &Access Time
1. –atime when file was last read.
2. –ctime when file data was last changed.
3. –mtimewhen file data or metadata last changed.
Syntax:- ~] # find –ctime day’s no.
(file modified less then 10 days ago.)
~] # find –atime 5
(looks for files whose last access time stamp exact 5 days ago.
~] # find –atime +5
(looks for file whose last access time stamp is more then 5 days ago.
Find & Permission
 Can match ownership by name or ID.
1. ~] # find /home –user username -o -uid 500
 Can match octal or symbolic permissions.
1. ~] # find -prem +755 (matches if mode is exact)
2. ~] # find -prem +222 (matches if anyone can write)
3. ~] # find -prem -222 (matches if everyone can write)
Find & Numeric Criteria:
 Many find criteria take numeric values
 ~] # find -size 1024kb
1. Files with a size of exactly 1 megabyte.
 ~] # find -size +1024kb
1. Files with a size over 1 megabyte.
 ~] # find -size -1024kb
1. Files with a size less then 1 megabyte.
UNIT-14
Network Clients
Firefox
 Fast, lightweight, Feature-rich web browser.
 Tabbed browsing.
 Popup browsing.
 Cookie management.
 Multi-engine search bar.
 Support for many popular plug-in.
 Themes and Extension.
Elinks
 Best linux text-based web client ( web browser )
 Full support for frames and SSL [ https websites ]
 Example:
 ~] # elinks http://www.redhat.com.
 Download manager
 Bookmark
wget
 Retrieves files via HTTP and FTP
 Non-interactive- useful in shell scripts
 Can follow links and traverse directory trees on the remote server
 Example
 wget http://www.download.com/songsplayer/mplayer.exe
Gaim
 Multi-protocol Instant messaging client
 Supports AIM, MSN, YAHOO, ICQ, Jabber, Gadu-Gadu, SILC, GroupWise Messenger,
IRC and Zephyr networks
 Plugins can be used to add functionality
gFTP
 Applications/Internet/gFTP
 Graphical FTP Client
 Allows Drag-and-Drop Transfers
 Optional secure transfer via ssh ( sftp )
Evolution
 Default Email Client software
 Can maintain multiple accounts and once
mutt
 Text based Email client
 Supports POP, IMAP and Local mail boxes
 Mappable hot keys.
ssh: Secure Shell
 ssh allows remote logins and remote command execution via a secure encrypted connection.
 Secure replacement for older remote-access tools.
 Allows authenticated, encrypted access to remote systems
 Example
 ssh root@station1.example.com
scp: Secure Copy
 scp works like cp, except it copies from one host to another in a secure encrypted channel
 Example
 scp somefile root@station1.example.com:
resync: Efficiently file sync
 Efficiently Copies files to or from remote systems.
 Users secure ssh connection for transport.
 Faster than scp.
 Syntax
 ~] # rsync source destination add.
 ~] # ssh root@ipaddress
 ~] # scp root@ipaddress:/root/dirname /root
 ~] # rsync root@ipaddress: /root/dirname /root
Introduction to Shell Scripting
What is shell script ?
 Shell scripts are text files that contains a series of commands or statements to be executed
 Shell scripts are useful for
 Automating commonly used commands
 Performing system administration and troubleshooting
 Creating simple applications
Creating Shell Scripts
 Create a file using vi text editor
 Use # for comments [ Information ]
 Enter commands related to scripts
 Make the script executable
 chmod a+x script_name
 To Execute the new script
 Place the script in a directory in the executable path
 Or Specify the absolute or relative path to the script on the command line
Exit Status
 Every command returns an exit status. The exit status will be a number in the range of 0 to
255 and it indicates whether or not the command ran successfully.
 0 for success, 1 to 255 for failure
 Exit status of most recently executed command is kept in the $? Variable just like return
values from shell functions
 Example:-
 echo $?
UNIT-15
Advanced Topic in Users, Group and Permissions
What is User Account ?
 When a computer is used by many people it is usually necessary to differentiate between the
users, for example, so that their private files can be kept private. This is important even if the
computer can only be used by a single person at a time, as with most computers. Thus, each user
is given a unique username, and that name is used to log in.
What is Group ?
 Is a collection of users which make easy for administrators to perform the task of administration
level when they need to apply permissions and restrictions with same level to many of the users,
then such permission and restrictions can be applied to related group.
The “root” user
 The root user: a special administrative account
● Same like “Administrator” we called in Win*
● Sometimes called the “superuser”
● root has complete control over the system
● An unlimited capacity to damage the system!
Creating Users
 useradd options user - Creates a new user.
● -c Assigns full name to user.
● -d Uses to define home folders location.
● -s Uses to define user's shell. (Use /sbin/nologin for users
you wish to restrict from having shell access).
● -g Add user to group ( Primary Group )
● -G Add user to group ( Secondary Group )
 usermod options user - Modifies user account
● Same options as useradd.
 userdel options user - Deletes user account.
● -r : Remove user's home directory.
 passwd user - Changes the password of the specified user.
● If no user is specified, will change the password of the current user.
Configuration Files
 /etc/passwd = file contains user database
 /etc/shadow = file contains user password database
 /etc/group = file contains group database
 /etc/gshadow = file contains group password database
User Information Commands
 Find out who you are
● whoami
 Find out what groups you belong to
● groups, id
 Find out who is logged in
● users, who, w
 Login/reboot history
● last
Linux file security
 Every file is owned by a UID and a GID.
 Every process runs as a UID and one or more GID’s. usually determined by who runs the
process.
 Three access categories.
 Process running with the same UID as the file (user).
 Process running with the same GID as the file (group).
 All other process (other).
What is Permission ?
 Specifies what rights are you granting to users to access the resources are available in the
computer, so that important resources such as files are protected from unauthorized users.
Methods of Implementing Permissions
 Symbolic Method
 Numeric Method
Applying Permission with Numeric Method
4. 4 (for read)
5. 2 (for write)
6. 1 (for execute)
Example: - ~] # chmod 640 file name
 If u wants to give the read, write, permission to owner then combined the both digit
code (4+2=6), and read permission to group (4), and for other’s on permission then (0). chmod
command is used to change access modes
 Numeric Method
● chmod 664 somefile  file name
(Grants Read and Write access to owner and group but read only it to and other. )
● chmod 600 somefile  file name
( Sets read and write permission to owner, with execute turned off, with others and group have
no permissions )
● chmod 444 somefile  file name
( Make the file world-readable )
Umask
 umask is a value which is subtracted from default to determine new file/ directory permissions
 Default permission for files is 666
 Default permission for directories is 777
 Default Permission – Umask = Effective Permission
● Non-Privileged Users umask is 002
 Files will have permissions of 664
 Directories will have permission of 775
● root’s umask is 022
● Example :-
● 666 – 002 = 664
● 666 – 244 = 422
● 777 – 222 = 555
● 777 – 027 = 750
Special Permission for directories:
 Sticky bit: the sticky bit for a directory sets a special restriction on deletion of files: with the
sticky bit set, only the owner of the file and super user (root) can delete files within the
directory. Sticky bit is (1) Example
 ~] # chmod 1777 dirname
 Sgid: files created in directories with the sgid bit set have group affiliations of the group the
directory. (2) Example
 ~] # chmod 2770 dirname
 Often both the sticky bit and sgid permission will be set on a group directory. Example
 ~] # chmod 3770 dirname
 Example
 ~] # chmod 4551 passwd
Others do not have write-
Others have readr
Group has executex
Group does not have write-
Group has readr
Owner has executex
Owner has writew
Others have execute
Owner has readr
x
Permissions
UNIT-16
The Linux File system in-Depth
Basic File System Types
 A file system is the logical structure and software routines that control access to the storage
space on disks.
 Unlike most operating systems, Linux supports several file system types.
 The Ext2 (Second Extended) file system is the most common Linux file system and is the
second version of the Ext file system
 The Ext2 file system was designed to overcome deficiencies found in the Ext file system
 The Ext file system can handle partitions up to 2 gigabytes (GB) in size, whereas Ext2 can
handle partitions up to 4 terabytes (TB) in size
Features of Ext2
 The Ext2 file system has many other advanced features including provision for filenames up to
255 characters long
 Ext2 also reserves disk space on the partition for the superuser. This means that if a disk
develops a problem, the superuser can still access that disk and rectify it
Ext3 file system
 In Linux 7.2, ext2 is the default file system
 Require check for consistency (e2fsck) when system is not properly shut down
 Ext => ext2 =>ext3
 Support 256 char filenames, 4 Tera byte max filesize
 Others MS-Dos, FAT32, NTFS, ISO9660
 Starting from Linux 7.3, ext3 is the default file system
 Provide stronger data integrity in event of unclean shutdown
 Check for consistency is needed only on rare hardware failure
 Higher throughput, as it is optimizes hard drive head motion
 Provide easy transition from ext2 to ext3
 other common filesystem are MS-DOS (FAT32, NTFS, ISO9660)
 The ext3 file system is essentially an enhanced version of the ext2 file system.
Advantages are:
Availability
 After an power failure or system crash (also called an unclean system shutdown), each
mounted ext2 file system on the machine must be checked for consistency by the e2fsck
program. This is a time-consuming process that can delay system boot time significantly,
especially with large volumes.
 The journaling provided by the ext3 file system means that this sort of file system check
is no longer necessary after an unclean system shutdown. The only time a consistency
check occurs using ext3 is in certain rare hardware failure cases, such as hard drive
failures.
Data Integrity
 The ext3 file system prevents loss of data integrity in the event that an unclean system
shutdown occurs. The ext3 file system allows you to choose the type and level of
protection that your data receives.
Partition and File System
 Disk drives are divided into partitions
 Partition are formatted with file system, allows users to store data
● Default file system: ext3, the Third Extended Linux File System
● Other common file systems:
● ext2 and vfat
● iso9660 ( typically used for CDs)
Links
 A link is a file that points to another file.
 “ln” creates a “link” from the original file to a new “file” in your directory.
 Most programs will access the link as if it was the file.
 This is similar to a “shortcut” in Windows.
 This allows for aliasing (when two or more names can exist for the same object)
 Easy way to point to a really long absolute pathname or filename
Using Links
 Two types of links can be created
● Symbolic ( Soft )
● Hard
ln -s main soft
( This will create an soft link of file “main” )
ln main hard
( This will create an hard link of file “main” )
Mounting the media
 “Mounting” means making a partition to access from an access point typically a folder to store
and access data from it.
Commands to mount media
mount /media/floppy = Mounts floppy drive to your computer
mount /media/cdrom = Mounts cdrom drive to your computer
mount /media/Device ID = Mounts usb disk to your computer
Commands to unmount media
umount /media/floppy = Unmounts floppy drive to your computer
umount /media/cdrom = Unmounts cdrom drive to your computer
umount /media/Device ID = Unmounts usb disk to your computer
Archive Files
 Archiving places many files into one target file
 Easier to back up, store, and transfer
 tar – Standard Linux archiving command
Using Archive files – tar command
 tar cvf archive_name files..
( To create archive file )
 tar tvf archive_name files..
( To display files under archive file )
 tar xvf archive_name files..
( To extract files from archive file )
 tar rvf archive_name files..
( To append archive file )
File Compression
 Results in smaller file size
 Text files can be compressed over 75%
 tar archives are often compressed
Compression Utilities
 gzip, gunzip
● Standard Linux compression utility
● Up to 75% compression for text files
 bzip2, bunzip2
● Newer Linux compression utility
● Generally achieves better compression than gzip
Using Compression
 gzip somefile
( To create compressed file )
 gunzip somefile
( To uncompress a compressed file )
 bzip2 somefile
( To create compressed file )
 bunzip2 somefile
( To uncompress a compressed file )
Note: - We can use z for gzip and j for bzip2 type of compression with tar
UNIT-17
Essential System Administration Tools
Red Hat Package Manager & Yum Server
RPM:- The RPM Package manager greatly simplifies the distribution, installation, upgrading,
and removal of software on Red Hat Enterprise Linux System.
The local RPM database is maintained in /var/lib/rpm. The database stores information
about installed packages such as file attributes and packages prerequisites. rpm is a backend for
other programs such as yum or system-config-packages. The tools provide significant advantages
such as automatic dependency resolution.
Primary RPM options:-
 rpm -I filename (for install)
 rpm -U filename (upgrade)
 rpm -F filename (for freshen)
 rpm -e filename (for erase)
 rpm -ivh filename (for update)
Output Option:-
 -v (Used for print package name)
 -h (Used for print hash marks)
RPM Queries:- RPM provide robust querying, which is invoked with rpm-q or rpmquery.
Query option fall into one of two categories: those that specify which packages to query, and those
that specify what information to retrieve. The first must be specified; the second defaults to the
package name.
Syntax: - rpm -qa |less
rpm -qf filename (show owning package)
rpm -qi package_name (general information)
rpm -ql package_name (lists files in package)
RPM Verification:- verifying an installed package compares the file sizes, permission, type,
owner, group, MD5 checksum, and modify time against the RPM database. Any inconsistency will
be reported. An installed package can also be verified against a package file as well:
Syntax: - rpm -V zip verifies the installed zip rpm against the RPM database.
rpm -Va verifies all installed RPMS against the RPM database.
rpm -Vp zip-2.3-8.i386.rpm verifies the installed zip package against the zip
pacakage file.

More Related Content

PDF
Basics of Linux
PDF
Linux Getting Started
ODP
Linux Introduction (Commands)
PPT
Basic 50 linus command
PPT
Linux commands and file structure
PPTX
Linux basics part 1
PDF
Lesson 1 Linux System Fundamentals
PPT
Linux Administration
Basics of Linux
Linux Getting Started
Linux Introduction (Commands)
Basic 50 linus command
Linux commands and file structure
Linux basics part 1
Lesson 1 Linux System Fundamentals
Linux Administration

What's hot (20)

PPTX
Terminal Commands (Linux - ubuntu) (part-1)
PPTX
Basics of-linux
PDF
17 Linux Basics #burningkeyboards
PPT
Linux Commands
PPTX
Linux basics
DOCX
Linux basic commands tutorial
PPT
Linux presentation
PPT
Unix/Linux Basic Commands and Shell Script
PDF
Linux commands
ODP
Linux commands
PPTX
Linux Command Suumary
DOCX
PDF
Basic linux commands
PPTX
Unix Linux Commands Presentation 2013
PDF
Quick Guide with Linux Command Line
PPT
Linux basic commands
DOC
Some basic unix commands
PDF
Lesson 3 Working with Files in Linux
PPT
A Quick Introduction to Linux
PPTX
Unix OS & Commands
Terminal Commands (Linux - ubuntu) (part-1)
Basics of-linux
17 Linux Basics #burningkeyboards
Linux Commands
Linux basics
Linux basic commands tutorial
Linux presentation
Unix/Linux Basic Commands and Shell Script
Linux commands
Linux commands
Linux Command Suumary
Basic linux commands
Unix Linux Commands Presentation 2013
Quick Guide with Linux Command Line
Linux basic commands
Some basic unix commands
Lesson 3 Working with Files in Linux
A Quick Introduction to Linux
Unix OS & Commands
Ad

Similar to Linux basic (20)

PPTX
Linux Systems Programming: Ubuntu Installation and Configuration
PPT
PPT
HISTORY, TYPES OF EMBEDDED LINUX, COMMANDS,
PPTX
I Am Linux-Introductory Module on Linux
PPT
Linux
PDF
beginner.en.print
PDF
beginner.en.print
PDF
beginner.en.print
PDF
Linux introduction (eng)
PPTX
Linux Basics.pptx
PPTX
Linux
PPT
Introduction to Unix
ODP
PPTX
Introduction, Features, Basic Commands and Distribution of LINUX
PPT
PPTX
Linux.ppt
PPTX
Unix_Introduction_BCA.pptx the very basi
Linux Systems Programming: Ubuntu Installation and Configuration
HISTORY, TYPES OF EMBEDDED LINUX, COMMANDS,
I Am Linux-Introductory Module on Linux
Linux
beginner.en.print
beginner.en.print
beginner.en.print
Linux introduction (eng)
Linux Basics.pptx
Linux
Introduction to Unix
Introduction, Features, Basic Commands and Distribution of LINUX
Linux.ppt
Unix_Introduction_BCA.pptx the very basi
Ad

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Basic Mud Logging Guide for educational purpose
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Cell Structure & Organelles in detailed.
Abdominal Access Techniques with Prof. Dr. R K Mishra
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
human mycosis Human fungal infections are called human mycosis..pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Final Presentation General Medicine 03-08-2024.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
VCE English Exam - Section C Student Revision Booklet
Pharma ospi slides which help in ospi learning
Microbial diseases, their pathogenesis and prophylaxis
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Basic Mud Logging Guide for educational purpose
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Insiders guide to clinical Medicine.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx

Linux basic

  • 1. UNIT-1 Idea and History of Linux First Linux version (UNIX) operating system developed by “Ken Thompson” and “Dennis Ritchie in “AT &T Bells Lab U.S.A” in 1970 work on CUI mode. 1984 GNU project was introduced (Graphical Not UNIX) it was an organization the aim of this organization to develop the clone of UNIX Operating System. 1987 Minix Kernel was introduce. Linux Origin: -  Linus Torvalds created its KERNEL in 1991.  with assistance from programmers around the world  first posted on Internet in 1991  Linux 1.0 in 1994; 2.2 in 1999  Today used on 7-10 million computers  with 1000’s of programmers working to enhance it What is Linux ?  A fully-networked 32/64-Bit Unix-like Operating System  Unix Tools Like sed, awk, and grep (explained later)  Compilers Like C, C++, Fortran, Smalltalk, Ada  Network Tools Like telnet, ftp, ping, traceroute  Multi-user, Multitasking, Multiprocessor  Has the X Windows GUI  Coexists with other Operating Systems  Runs on multiple platforms
  • 2.  Includes the Source Code Red Hat Enterprise Linux  Commercial Distribution  Enterprise-targeted operating system  Focused on mature open source technology  12-18 month release cycle  Versions available started from 2.1, 3.0, 4.0 now 8.x  Support available up to 24 x 7 coverage plans  Supports many processor architectures Intel x86-compatible, Intel Itanium 2, AMD64, IBM PowerPC on eserver iSeries and eServer pSeries and IBM Mainframe on eServer zSeries and S/390 The Fedora Project  Red Hat-sponsored open source project  Focused on latest open source technology  Rapid four to six month release cycle  Available as free download from the internet  An open, community-supported proving ground for technologies which may be used in upcoming enterprise products  Red Hat does not provide formal support for Fedora Project What is Kernel? The kernel is the heart of the whole operating system. It manages communication with hardware, decides which processes to run, and provides each process with an isolated, virtual address space in which to run. The kernel is what your boot loader, GRUB , loads into memory. The kernel loads device driver modules What is "the shell"? The shell is a program that takes your commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix computer. Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the shell. What is Boot loader ? boot loader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the operating system kernel software. The kernel, in turn, initializes the rest of the operating system GRUB (GRand Unified Bootloader), which is installed by default, is a very powerful boot loader. GRUB can load a variety of free operating systems, as well as proprietary operating systems with chain- loading (the mechanism for loading unsupported operating systems, such as DOS or Windows, by loading another boot loader). What is SWAP Partition ? swap partitions are used to support virtual memory. In other words, data is written to a swap partition when there is not enough RAM to store the data your system is processing. Size of SWAP ?  At least 256 MB  Twice the amount of RAM on your machine  Swap should equal 2x physical RAM for up to 2 GB of physical RAM, and then 1x physical RAM for any amount above 2 GB, but never less than 32 MB.  SWAP can also used after the installation  Red Hat Enterprise Linux supports up to 32 swap files Sample Partition Structure Mount Point Size
  • 3. /boot 128 MB / 2048 MB /usr 2048 MB /var 512 MB /home 512 MB SWAP Use recommended size Similarity Between Linux & Windows  Both are operating system.  Multi-users.  Multi-tasking & processing.  Works in CUI & GUI mode. Dissimilarity Between Linux & Windows Linux Windows 1. Economical to use 1. Not Economical to use 2. More Security 2. Less Security 3. Mostly work in CUI 3. Mostly Work in GUI 4. Workstation & Server 4. Client & Server Multi-tasking:- Multiple task can run process one by one at a time. Multi-processing:- Multiple Programs can perform at a time Principle of Linux 1. Everything is a file:- The UNIX security module is based around the security of files by treating everything is a file. You can secure access to Hardware in the same way as you secure access to document. 2. Small, Single purpose program:- UNIX provide many small utility that performs one task very well. 3. Ability to chain programs together to perform complex task:- A core design feature of UNIX is that the output of one programs can be input for another. 4. Configuration data stored in text:- all the data is stored in text b’coz text is Universal interface and many UNIX utility exist to manipulate text. Storing Configuration in text allows an administrator to move a Configuration from one Machine to another easily. Open Source Software  When programmers on the Internet can read, redistribute, and modify the source for a piece of software, it evolves  People improve it, people adapt it, people fix bugs. And this can happen at a speed that, compared to conventional software development, seems astonishing Open source software refer to the software in which the source code is freely available to all users to modify their Linux as their need. Website http://www.opensource.org/docs/defination.php
  • 4. What is WINDOWS? W- Wide I- Interactive N- Network D- Development O- Office W- Work S- Solutions Distributors of Linux 1. Red hat Supported by RHEL 2. Suse Supported by NOVELL 3. Turbo Linux Supported by US & Japenese 4. Fedora Linux Supported by RED HAT 5. Sol Supported by Server Optimized Linux End of UNIT-1
  • 5. UNIT- 2 Linux Usage Basic Login in to a Linux System:- Red Hat Linux provide two type of login method.  Two type of login Screen :- Virtual Console [text based] and Graphical Login [display manager]  Login using login name and password.  Each user has a home directory for personal file storage.  Red Hat provides by default six virtual consoles that are [ctrl+alt+f1] to [ctrl+alt+f6].  [ctrl+alt+f7] is used for Graphical mode.  Init 6 and reboot command is used to restart.  Elements of ‘X’ Windows System:-  The ‘X’ Windows system is Linux’s Graphical subsystem  “X” Org. is particular version of the X windows system used by Red Hat.  Look & Behavior Largely Controlled by the Desktop Envirment.  Two Desktop environments provided by Red Hat. ---1. GNOME the default Simple view of GNOME Desktop  desktop environment. 2. KDE an alternate desktop envoirment.
  • 6. Simple view of KDE Desktop  Start “X” switch text base to graphical. Following commands are used to create a new file  NANO Easy, Editor, Simple  VI Easy, Editor, Simple  VIM Advanced featured with Encryption  GVIM Basic File editing – vi editor  vi - the basic text editor  three modes ● Command mode <= default startup ● Insert mode ● ex mode  vi test <= a typical example ● Enter insert mode <i> and <CR> ● Enter <ESC> return to command mode ● Navigate the cursor ● h move cursor left ● j moves cursor down ● k moves cursor up ● l moves cursor right Some Simple Commands  ls = list the files and directory  date = display date and time  cal = display calendar  clear = clear the screen  pwd = prints the name of current working directory  mkdir = creates the directory
  • 7.  rmdir = removes the directory  cd = changes the directory  cat = display the contents of file  rm = removes the files  cp = copy the files and directory  mv = move and rename ( files and directories )  touch = updates the file/directory time-stamps  less = pager command  more = pager command Commands  G = go to last line in file  1G = go to first line in file  H = go to first line on screen  M = go to middle line on screen  L = go to last line on screen  z<Enter> = make current line first line on screen  z- = make current line last line on screen  !!date = Inserts the current date and time in to file  !}sort = Sorts the data of your file  !}fmt -66 = formats the data of your file in to 66 column width Ex mode : Search and Replace command :%s/big/small :%s/big/small/g To display the list of files & Directories we use “ls” command. Blue Color “Directories” and White Color files. # it shows that login with Privilege User $ it shows that login with Non- Privilege user History command is used to show the past command. Reboot, init 6, command is used to restart the system. Power off Command is used to shutdown the system. If you want your system shut down after your particular time like after 2 minute then command is ] # shutdown –h 2 [ -h for halt, 2 for 2 minute] Creating directory:- ] # mkdir dir name Entering into dir:- ] # cd dir name Listing directory content:-  Ls to show the list of files & directory  Ls –a include hidden files  Ls –l display extra information  Ls –r recurse through directories  Ls –ld directories and symlink information Creating a user: - ] # Useradd username ] # passwd username 1. mkdir to create a directory (# mkdir dirname) 2. cd to change the directory (# cd dirname) 3. cd .. to come out from previous directory (# cd ..) 4. cd – to go at previous working directory (# cd -)
  • 8. 5. cd to go at the Home (~) directory (# cd) 6. pwd to display present working directory (# pwd) 7. rm to remove the file ( # rm -{option} file name. Options are –i interactive -r recurse -f forcefully 8. rmdir to remove empty directory (# rmdir dirname) 9. rmdir –r dirname to remove any file & directory are exists. The location of a file and directory can be specified by two methods Absolute Relative 1. Begin with a forward slash 1. Do not begin with slash 2. Complete “road map” to file location 2. Specify location relative to your Current working directory. 3. Can be used any time you wish to specify 3.Can be used as a stored way to a file name. specify a file name. End of UNIT-2 Unit-4 Browsing the file system We have already discussed or learned in UNIX all, information treated as a file. Single disk can store thousands of files or organizing the data on the disk the o/s provides a file system. There are three types of file. 1. Ordinary & Regular file:- all files are created by a user come under these categories. 2. Directory file:- for each directory there is file by the same name as the directory. Which contain information about files under that directory? 3. Device file:- device file are special types typically associated with input/output device such as Printer, Tap Drive, HDD, FDD, CD-Drive. Structure of the file system Linux file system has a tree structure or hierarchical structure that is file & sub directories can be stored in the directory. ~] # you are work in home directory.
  • 9. /] # you are work in root directory. 1. /bin:- this is the binary directory. Which contain the executable files? When a program is installed its binary files are stored here. 2. /dev:- dev stand for device that contains files that point to the hardware that make up the system. 3. /etc:- this folder contains various configuration files that can be manually edited to affect the system charge. 4. /lib:- lib means “Library” files frequently used system files needed by program or the operating system are stored here just like library files stored in “C:windowssystem” in windows o/s. 5. /usr:- Non-critical files are stored in this directory which contain a copy of most of the directories in the root. 6. /var:- the various folder contains just that various files such as log file. 7. /tmp:- this is the directory that used by application for storing temporary files. 8. /opt:- the option directory stored add on component such as desktop envoirment database . 9. /mnt:- all storage media other than Linux partition are mounted here. 10. /root:- this is the home directory of the root user 11. /boot:- the boot loader files are stored here. 12. /home:- this is the directory that contain user’s file. 13. The /proc/ Directory - contains special files that either extract information from or send information to the kernel. Examples include system memory, cpu information, hardware configuration etc. 14. The /sbin/ Directory - stores executables used by the root user. The executables in /sbin/ are used at boot time, for system administration and to perform system recovery operations. Copying files and Directories  If the destination is a directory, the copy is placed there  If the destination is a file, the copy is overwrites the destination.  If the destination does not exist, the copy renamed. Command – cp source add destination add Command – cp –[option] filename /dirname -I = ask me before overwriting a file. -r = recursively copy an entire directory tree. -p = permission, ownership, & time stamps. Move and renaming files & directory Move command is used to move a file or directory from source to destination. OR Move command is used to rename a file or directory Note: - if the destination is not reachable then it renames the file or directory. Command: - mv [option] filename destination For example: - create two directory named aa, bb. ~] # mkdir aa bb ~] # cd aa aa] # nano hcl
  • 10. aa] # mv hcl /root/bb aa] # cd ~] # cd bb bb] # ll Now your file hcl has moved from aa to bb. Nautilus:- graphical file system browser. End of UNIT-4 Unit-5 User, Group, and Permission What is User Account ?  When a computer is used by many people it is usually necessary to differentiate between the users, for example, so that their private files can be kept private. This is important even if the computer can only be used by a single person at a time, as with most computers. Thus, each user is given a unique username, and that name is used to log in. User:-  Every user is assigned a unique user ID no. (UID). (UID0) identify root.  User’s name and UID are stored in /etc/passwd.  User and assigned a home directory and a program that is run when they log in casually a shell.  User can not read, write or execute each other, files without permission.  Note to see UID run the ~] # Cat /etc/passwd. What is Group ?  Is a collection of users which make easy for administrators to perform the task of administration level when they need to apply permissions and restrictions with same level to many of the users, then such permission and restrictions can be applied to related group. Group:-  User’s are assigned to a group.  Each group is assigned a unique group ID no. (GID).  GID is stored in /etc/group.  Each user is given their own private group. Can be added to other groups for additional access.  All users in a group can share a file that belongs to the group.  Note to see GID run the ~] # Cat /etc/group The “root” user  The root user: a special administrative account ● Same like “Administrator” we called in Win* ● Sometimes called the “superuser” ● root has complete control over the system ● An unlimited capacity to damage the system! What is Permission ?  Specifies what rights are you granting to users to access the resources are available in the computer, so that important resources such as files are protected from unauthorized users.
  • 11. Permission Types Permissions- Symbolic Method Four symbols are used when displaying permission.  R: - permission to read a file or list a directories content.  W: - permission to write a file or create and remove files from a directory.  X: - permission to execute a program or change into a directory and do a long listing of the directory.  -: - no permission in place of the r, w, x. Permissions- Numeric Method  Four numbers are used when displaying or applying permissions ● 4 Permission to read a file or list a directory’s contents ● 2 Permission to write to a file or create and remove files from a directory ● 1 Permission to execute a program or change into a directory and do a long listing of the directory ● 0 no permission ( in place of the 4, 2, or 1 ) Examining Permission  File permission may be viewed using ~] $ ls –l /bin/login -rwxr-xr-xl root root 19080 Apr 1 18:26 /bin/login  File type and permissions are represented by a 10 character string. Changing File Ownership  Only root can change a file’s owner.  Only root or the owner can change a file’s group.  Owner ship is changed with chown.  ~] # chown username file/dirname  Group ownership is changed with chgrp  ~] # chgrp groupname file/dirname.  To change access mode with chmod  ~] # chmod mode file  Where mode is 1. U, G, or O for User, Group, or Other 2. + sign for grant the permission. 3. – sign for deny the permission. 4. r, w, x, for Read, Write, Execute. For Example:- ~] # chmod u=rwx, g=rw, o=r file name ~] # chmod ugo +r file name (for read permission to all). ~] # chmod a= rwx filename Changing permission with numeric method  Uses a tree digit mode number. 1. First digit specifies owner’s permission. 2. Second digit specifies group’s permission. 3. Third digit specifies other’s permission.
  • 12. Applying Permission with Numeric Method 1. 4 (for read) 2. 2 (for write) 3. 1 (for execute) Example: - ~] # chmod 640 file name  If u wants to give the read, write, permission to owner then combined the both digit code (4+2=6), and read permission to group (4), and for other’s on permission then (0). chmod command is used to change access modes  Numeric Method ● chmod 664 somefile  file name (Grants Read and Write access to owner and group but read only it to and other. ) ● chmod 600 somefile  file name ( Sets read and write permission to owner, with execute turned off, with others and group have no permissions ) ● chmod 444 somefile  file name ( Make the file world-readable ) Changing Permission Nautilus  Nautilus can be used to set the permission and group membership of files and dir. 1. sIn a nautilus window right click on a file. 2. Select properties from the content menu. 3. Select the permission tab. Note: - To check the permission use ls –l. If we change the permission of any file and dir then their colors become green. To add a user in a group ~] # usermod –G groupname username To change the ownership of a user to other user:- Log in with root’s home directory ~] # cd /home Home] # chown username username End of UNIT-5 Unit-6 Using the bash shell What is shell script ?  Shell scripts are text files that contains a series of commands or statements to be executed  Shell scripts are useful for
  • 13.  Automating commonly used commands  Performing system administration and troubleshooting  Creating simple applications  Manipulation of text or files. Shell makes an interface between Users & Kernel. There are three main shells for UNIX is: - 1. Bourn Shell 2. C Shell 3. Korn Shell Now a days Bash shell become popular in Linux O/S. Broun again shell (Bash shell) was released Brain fox & chief Remey as part of the free software foundation. The GNU project features of Bash shell are: - 1. Input and output redirection. 2. Use of wild card. 3. Command line editing. 4. Zilde representation 5. Built- in shell command & Variables. 6. Command history and aliasing. Command line Shortcuts 1. (*) Match zero or more characters. 2. (?) Match any single. 3. (0-9) Match a range of number. 4. (abc) Match any of the character in the list. 5. (^abc) Match all character in the list. Notes: - Remove all files in extension .mp3 we use. Syntax: - ~] # rm *mp3 Remove all files in extension .txt we use. Syntax: - ~] # rm *txt To show the file which have second character with ‘O’ alphabate? Syntax: - ~] # echo ?O* To show the file which have Third character with ‘M’ alphabate? Syntax: - ~] # echo ??m* ~] # ls a press tab key two times. ~] # cat a press tab key two times. (This command is used to show the file & directories start with letter ‘a’ as like ajay.txt) ! char repeat last command that start with character. Syntax: - ~] # ! char Example: - ~] # ! d (any character alphabate) ! num repeat last command by this no. in history output. Syntax: - ~] # ! num Example: - ~] # !5 ~] # mkdir –P work/{inbox,outbox,pending}/{normal,urgent,important} Work Inbox Outbox Pending Normal Urgent Imp Normal Urgent Imp Normal Urgent Imp To Check This: - ~] # ls Then it shows (work directory) ~] # cd work
  • 14. Work] # ls Then it shows (inbox, outbox, pending directory) ~] # cd inbox Inbox] # ls Then it shows (normal, urgent, important sub directory) Command Editing Trick ~] # ctrl –a moves to beginning of line. ~] # ctrl –e moves to end of line. ~] # ctrl –u delete to end beginning of line. ~] # ctrl –k delete to end of line when the cursor in the beginning of line. ~] # ctrl –arrow moves left or right by word. GNOME Terminal Application ---- Accessories ---- Terminal Graphical terminal emulator that supply multiple “tabbed” shells.  Ctrl + Shift + T create a new tab.  Ctrl + Pgup/Pgdn Switch to next/previous  Ctrl + Shift + W close the tab.  Ctrl + Shift + C copies selected text.  Ctrl + Shift + V paste text to the prompt Creating Shell Scripts:- Step 1:- use such as ‘VI’ to create a text file containing commands. First line contain the magic shebang sequence: # ! Like # !/bin/bash Comment your scripts ! Comments start with # Make a Script Open a new file with ‘VI’ editor like ~] # vi filename and type the following ~] # vi filename Press “I” for insert mode. # !/bin/bash # this script display Echo “the date & time are $ (date)” Echo “your working directory is $ (pwd)” Echo “your files & Dir. Are $ (ls -a) Echo “your virtual consoles open are $ (who) Press “ESC” key :wq To run the file ~] # ./filename Step 2:- Make the script executable ~] # chmod u+x filename To execute the new script: 1. Place the script file in a directory in a executable path 2. Specifying the absolute or relative path to the script on the command line.
  • 15. Writing Programs using bash scripting Sample Program 1  # Simple Program for users input  echo -n "Enter Your Name :"  read a  echo -n "Enter Your Age :"  read b  echo "Hello Dear $a your age is $b Years" Sample Program 2  # Addition of A and B number  echo -n "Enter First number :"  read a  echo -n "Enter Second number :"  read b  c=`expr $a + $b`  echo "Result is" $c Sample Program 3  # Multiply A and B  echo -n "Enter First number :"  read a  echo -n "Enter Second number :"  read b  c=`expr $a * $b`  echo "Result is" $c Sample Program 4  # Divides A from B  echo -n "Enter First number :"  read a  echo -n "Enter Second number :"  read b  c=`expr $a / $b`  echo "Result is" $c Sample Program 5  # Subtract B from A  echo -n "Enter First number :"  read a  echo -n "Enter Second number :"  read b  c=`expr $a - $b`  echo "Result is" $c Sample Program 6  # To Check Bigger number between two numbers  echo -n "Enter First number :"  read a  echo -n "Enter Second number :"  read b  if [ $a -gt $b ]; then  echo "A is BIG"  elif [ $a -eq $b ]; then  echo "Both are equal"  else  echo "B is BIG"  fi Sample Program 7
  • 16.  # To show table of number given by user  i=1  echo -n "Enter any number : "  read n  while [ $i -le 10 ]  do  echo "$n X $i = `expr $i * $n`"  i=`expr $i + 1`  done Sample Program 8  #Checks to see hosts 192.168.0.1 to 192.168.0.10 are alive  for n in {1..10}; do  host=192.168.0.$n  ping -c2 $host &> /dev/null  if [ $? = 0 ]; then  # print host names 30 char wide and left justified  printf "%-30s is aliven" $host  else  printf "%-30s is NOT aliven" $host  fi  done UNIT-7 Standard Input / Output and Pipes One of the most important features of Linux (and UNIX) is the ability to redirect a command’s input, output, and error data. Linux provides the three I/O channel to programs. 1. Standard Input Keyboard by default 2. Standard Output Terminal Windows by default 3. Standard error Terminal Windows by default Redirecting to file 1. > Redirect STD OUTPUT to file 2. 2> Redirect STD ERROR to file 3. &> Redirect all output to a file Common Redirection operators 1. Command >filename Direct standard output command to file. 2. Command >>filename Append standard output command to file. 3. Command <filename Send file as input to command 4. Command 2>filename Redirected error message from command to file. 5. Command 2>>filename Append error message from command to file. 1. Input Redirection:- any text input enter from the keyboard redirect in to specified file. ~] # cat >filename, ~] # ls –l>filename 2. Output Redirection:- instruct to shell to redirect to a command output into the specified file instead of the terminal. ~] # cat <filename 3. Error Redirection:- ~] # xyz 2>error message Experiment of upper command by the following process First of create a user on root and login to that user and follow the step 1. ~] # find / -name passwd 2. ~] # find /etc –name passwd 3. ~] # Find /etc –name passwd >raj (filename) {send the result in raj and show remaining error}. 4. ~] # cat raj (filename) {raj show the result}. 5. ~] # find /etc –name passwd >>raj (filename) {add the result in raj which comes in command number 3}.
  • 17. 6. ~] # cat raj {show the total result in raj} 7. ~] # cat <raj {command 6 and 7 has same output we use command as well as command 7}. 8. ~] # find /etc –name passwd 2>raj2 (filename) {send the errors in raj2(filename) and show result}. 9. ~] # cat raj2 (filename) or ~] # cat <raj2 (filename) {to see the error are in raj2 (filename)}. 10. ~] # find /etc –name passwd 2>>raj2 (filename) {add the error which are comes in command 8}. 11. ~] # cat raj2 (filename) or ~] # cat <raj2 (filename). 12. ~] # find /etc –name passwd &>raj3 (filename). 13. ~] # cat raj3 (filename). 14. ~] # find /etc –name passwd >aa >bb {to send all the result in file named aa and error in file named bb}. 15. ~] # cat aa {to see result}. 16. ~] # cat bb {to see error}. Redirecting STDOUT to a Program (Piping)  Pipes (the | character) can connect commands. (command1 | command2)  Sends STDOUT of command1 to STDIN of command2 instead of the screen.  STDERR is not forwarded across pipes.  PIPE is used to add two or more commands. Ex ~] # ls –l | more  Tr translate the upper case into lower case and lower case into upper case. Original file will be unchanged.  Syntax:- ~] # tr ‘a-z’ ‘A-Z’ <filename Syntax:- ~] # tr ‘A-Z’ ‘a-z’ <filename Redirecting STDOUT to a Program Examples  Less: view input one page at a time. ~] # ls –l /etc |less {input can be searched with /}.  Lpr: Send input to a printer. ~] # echo “test print” | lpr or ~] # echo “test print” | lpr –p printer_name.  Mail: Send input via e-mail. ~] # echo “test mail” | mail-s “test” user@example.com Scripting for loops Performing actions on each member of a set of values. Syntax: make a file with VI editor #!/bin/bash # alive2.sh # checks to see if hosts 192.168.1.1-192.168.1.20 are alive # iterate through IP addresses For n in {1…20}; do Host=192.168.1.$n Ping –c2 $host &> /dev/null If [$? =0]; then Echo “$host is up” Else Echo “$host is down” Fi Done Press ‘ESC’ key : Wq ~] # chmod u+x raj (filename). ~] #. /raj (filename).
  • 18. Filter Command ~] # grep. /etc/passwd {it show the content of file after filtering}. Sort Command ~] # sort color (it show the alphabetical content). ~] # ls –l |sort Mutt Command (this command is a text-based mail client). UNIT-8 Test Processing Tools Introduction to String Processing Head and Tail  Head shows the first 10 lines of a file ● Try head /etc/somefile ● Try head -n 5 /etc/somefile (shows the first 5 lines of the file)  Tail shows the last 10 lines of a file ● Try tail /etc/somefile ● Try tail -n 5 /etc/somefile (shows the last 5 lines of the file) wc, sort, uniq , cut and paste  wc “Word Count” used to count the line, word, character in the file.  Syntax ~] # wc -l filename (for count the line) ~] # wc -w filename (for word count) ~] # wc -c filename (for column count) ~] # wc -m filename (for the character count) ● Options ( -l (for line), -w(for word), -c(for column) )  sort “Sorting Order” it is used to sort the data into ascending or descending order but original file will be no change.  Syntax:- ~] # sort –r filename {for descending sort} ● ~] # sort filename {for ascending} ● ~] # sort –n filename {for ascending numeric sort ● ~] # sort –nr filename {reverse numeric sort} ● ~] # sort –u filename {unique sorting} ● sort OPTIONS somefile ● Options ( -r, -n )  uniq “Removes duplicate lines in a file” ● -u to show only truly uniq ● -d to show lines that are repeated in the input ● -c to count lines  cut “ Display specific columns of the file data  Syntax~] # cut -c2-5 filename ~] # cut –f3 –d: /etc/passwd  paste “Paste files together” ~] # paste file1.txt file2.txt > file3 aspell, expand look and sed  aspell “To check spelling in file “  Syntax ~] # aspell check filename  expand “Expand tabs into spaces” ● expand tabfile.txt > result.txt  Look give the matches related work from directories.
  • 19.  Syntax~] # look word  Sed (stream editor) use to search and replace pattern but original file will be unchanged.  Syntax~] # sed ‘s/Ajeet/amit’ filename ~] # sed ‘s/Ajeet/amit’ filename >new filename (saving changes in another file). String Processing with Regular Expressions Grep, sed, awk, diff  grep This command is used to search a word in a file.  Syntax ~] # grep ‘[Cc]at filename ~] # grep -i ‘[f]rog filename (i- represents case –insenstivity)  Syntax ~] # grep -A3 ‘cat’ filename (A stand for after) ~] # grep -B3 ‘cat’ filename (B stand for befor) “ Prints lines of files where a pattern is matched ● grep amit /etc/passwd  sed “ Stream Editor :- Reads a file ; writes out the data performe search and replace “ original will be unchanged. ● sed ‘s/big/small/’ somefile ● sed ‘s/big/small/g’ somefile  awk “ Programming language for editing text “ ● awk ‘ /bash/ { print } ‘ /etc/passwd  diff this command is used to make a difference between 2 files. Syntax~] # diff file1 file2 UNIT-9 VIM: An Advanced Text Editor Vim stand for (visual improved editor):- it is a advance version of VI editor it create the text file in encrypted form. Syntax:- vim -x filename
  • 20. Introduction of VIM:-  Newer version of VI the standard UNIX text editor. 1. Executing VI runs VIM by default.  GVIM- graphical version of VIM. 1. Application + Programming VI 2. Providing by VIM –x 11 Package Advantage of VIM:  Speed: do more with fewer keystrokes.  Simplicity: no dependence on mouse/GUI  Availability: included with most UNIX like uses. Disadvantage of VIM:  Difficulty: steeper learning curve than simpler editors.  Keystroke behavior is dependent upon VIM’s mode In this VIM or VI editor you have three mode. 1. Command mode: (Default) move cursor, cut, text, change mode. 2. Insert mode: modified text. 3. Ex-mode: save & quit etc. Moving Around command mode:  Move by word w, b  Move by sentence ), (  Move by Paragraph }, {  Jump by line X XG  Jump by end line G Shortcut of Command mode:  A it stand for append to the end line.  I insert at beginning of the line.  o insert a new line down side.  O insert a new line up side.  U used for undo  For mouse: h-left, j-down, k-up, l-right. Command for word replacement: ~] # :%s/old word/new word Manipulating Text Command mode Word Change (Replace) Delete (Cut) Yank (Copy) Line CC dd yy Letter cl dl yl Word cw dw yw Sentence ahead c) d) y) Sentence behind c( d( y( Paragraph above c{ d{ y{ Paragraph behind c} d} y}
  • 21. Line wise Paste  p used for paste below the line  P used for paste above the line Character wise & word wise  p used for paste after the cursor  P used for paste before the cursor UNIT-10 Basic System Configuration Tools IPAddressing  Is a 32bit Logical Address which make computer to communicate to each others using TCP/IP protocol.  Defined in different classes From A to E  Class A= 1 to 126  Class B = 128 to 191  Class C = 192 to 223 We can assign IPAddress to computer by using two methods 1. Static [ Manually ] 2. Dynamic [ Using DHCP Server ] Network Configuration Commands  ifconfig  Used to view the properties of active and inactive network interfaces  ifconfig  Ifconfig –a = to display information about inactive network interface
  • 22.  ifup / ifdown  Used to activating and deactivating a network interface  ifdown eth0  ifup eth0  mii-tool  Tool allows a system administrator to view, monitor, log and change the negotiated speed of Ethernet network cards  mii-tool –v = to view the current status of network interface card  mii-tool –v --force 100baseTx-FD eth0  To change the negotiated speed of Ethernet network card Network Configuration Utilities  neat / neat-tui  Text-based network configuration tool  Only writes config files. Does not activate device or changes. Use ifup/ifdown to active changes or restart the network service  Used by kudzu when new network card found at boot time  system-config-network  GNOME-based network configuration tool  Can be launched by a non-privileged user, but requires authentication as root. Printing in Linux  Printer may be local or networked.  Print requests are sending to queues.  Queued jobs are sent to the printer on a first come first serve basis.  Jobs may be cancelled before or during the printing.  Lpr command is used to print the file. System-config-printer UNIT-11 Investing and Managing Processes What is a Process?  A process in an executing program with several components and properties.  A process is a shell command or a program in execution.  When you log in, a process is created. This process is executing the shell  When you execute a shell command, a new process is created. When the command terminates, the new process dies.  A single user can have many processes executing at the same time ps command  The command ps is used to determine the status of active processes. The command returns the process id (PID) number and other information such as the amount of CPU time the process has used (TIME) and the command which invoked the process (CMD).  Options may be combined. top command  The command top is used to show a real-time view of Linux tasks  top can be used to display the CPU/memory usage of each task  top Terminate Processes  kill is used to terminate processes or to send signal to processes.  Examples: ● kill PID ● Terminate the process with the process id (PID).
  • 23. UNIT-12 Configuring the Bash Shell What is Bash Shell? It is the default shell for Linux operating system it was introduced in 1975. Aliases:-  Aliases let you create shortcuts to commands.  Use alias by it self to see all set aliases.  Use alias followed by an alias name to see alias value.
  • 24. UNIT-13 Finding and Processing Files Locate:-  Queries a pre-built database of paths of files on the system. 2. Database must be updated by administrator. 3. Full path is searched, not just file name.  May only search directories where the user has read and execute permission. Note:- Locate command is used to search the full path of file, and display if locate command does not run then firstly run ‘updatedb’ command at root login after that run “Locate” command. Syntax:- ~] # locate dirname slocate and find  slocate “ Search for files “ ● slocate somefile  find “ Search for files “ ● find /home –name somefile ● find /home –iname somefile [ case-insensitive search ] ● find /home –user amit –group amit somefile ● find /home –perm 755 ● find /home –size 1000kb ● find /home –user username ● find /home –user username –o –user username Find &Access Time 1. –atime when file was last read. 2. –ctime when file data was last changed. 3. –mtimewhen file data or metadata last changed. Syntax:- ~] # find –ctime day’s no. (file modified less then 10 days ago.) ~] # find –atime 5 (looks for files whose last access time stamp exact 5 days ago. ~] # find –atime +5 (looks for file whose last access time stamp is more then 5 days ago. Find & Permission  Can match ownership by name or ID. 1. ~] # find /home –user username -o -uid 500  Can match octal or symbolic permissions. 1. ~] # find -prem +755 (matches if mode is exact) 2. ~] # find -prem +222 (matches if anyone can write) 3. ~] # find -prem -222 (matches if everyone can write)
  • 25. Find & Numeric Criteria:  Many find criteria take numeric values  ~] # find -size 1024kb 1. Files with a size of exactly 1 megabyte.  ~] # find -size +1024kb 1. Files with a size over 1 megabyte.  ~] # find -size -1024kb 1. Files with a size less then 1 megabyte. UNIT-14 Network Clients Firefox  Fast, lightweight, Feature-rich web browser.  Tabbed browsing.  Popup browsing.  Cookie management.  Multi-engine search bar.  Support for many popular plug-in.  Themes and Extension. Elinks  Best linux text-based web client ( web browser )  Full support for frames and SSL [ https websites ]  Example:  ~] # elinks http://www.redhat.com.  Download manager  Bookmark wget  Retrieves files via HTTP and FTP  Non-interactive- useful in shell scripts  Can follow links and traverse directory trees on the remote server  Example  wget http://www.download.com/songsplayer/mplayer.exe Gaim  Multi-protocol Instant messaging client  Supports AIM, MSN, YAHOO, ICQ, Jabber, Gadu-Gadu, SILC, GroupWise Messenger, IRC and Zephyr networks  Plugins can be used to add functionality gFTP  Applications/Internet/gFTP  Graphical FTP Client  Allows Drag-and-Drop Transfers  Optional secure transfer via ssh ( sftp ) Evolution  Default Email Client software  Can maintain multiple accounts and once mutt  Text based Email client  Supports POP, IMAP and Local mail boxes  Mappable hot keys. ssh: Secure Shell
  • 26.  ssh allows remote logins and remote command execution via a secure encrypted connection.  Secure replacement for older remote-access tools.  Allows authenticated, encrypted access to remote systems  Example  ssh root@station1.example.com scp: Secure Copy  scp works like cp, except it copies from one host to another in a secure encrypted channel  Example  scp somefile root@station1.example.com: resync: Efficiently file sync  Efficiently Copies files to or from remote systems.  Users secure ssh connection for transport.  Faster than scp.  Syntax  ~] # rsync source destination add.  ~] # ssh root@ipaddress  ~] # scp root@ipaddress:/root/dirname /root  ~] # rsync root@ipaddress: /root/dirname /root Introduction to Shell Scripting What is shell script ?  Shell scripts are text files that contains a series of commands or statements to be executed  Shell scripts are useful for  Automating commonly used commands  Performing system administration and troubleshooting  Creating simple applications Creating Shell Scripts  Create a file using vi text editor  Use # for comments [ Information ]  Enter commands related to scripts  Make the script executable  chmod a+x script_name  To Execute the new script  Place the script in a directory in the executable path  Or Specify the absolute or relative path to the script on the command line Exit Status  Every command returns an exit status. The exit status will be a number in the range of 0 to 255 and it indicates whether or not the command ran successfully.  0 for success, 1 to 255 for failure  Exit status of most recently executed command is kept in the $? Variable just like return values from shell functions  Example:-  echo $? UNIT-15 Advanced Topic in Users, Group and Permissions What is User Account ?  When a computer is used by many people it is usually necessary to differentiate between the users, for example, so that their private files can be kept private. This is important even if the
  • 27. computer can only be used by a single person at a time, as with most computers. Thus, each user is given a unique username, and that name is used to log in. What is Group ?  Is a collection of users which make easy for administrators to perform the task of administration level when they need to apply permissions and restrictions with same level to many of the users, then such permission and restrictions can be applied to related group. The “root” user  The root user: a special administrative account ● Same like “Administrator” we called in Win* ● Sometimes called the “superuser” ● root has complete control over the system ● An unlimited capacity to damage the system! Creating Users  useradd options user - Creates a new user. ● -c Assigns full name to user. ● -d Uses to define home folders location. ● -s Uses to define user's shell. (Use /sbin/nologin for users you wish to restrict from having shell access). ● -g Add user to group ( Primary Group ) ● -G Add user to group ( Secondary Group )  usermod options user - Modifies user account ● Same options as useradd.  userdel options user - Deletes user account. ● -r : Remove user's home directory.  passwd user - Changes the password of the specified user. ● If no user is specified, will change the password of the current user. Configuration Files  /etc/passwd = file contains user database  /etc/shadow = file contains user password database  /etc/group = file contains group database  /etc/gshadow = file contains group password database User Information Commands  Find out who you are ● whoami  Find out what groups you belong to ● groups, id  Find out who is logged in ● users, who, w  Login/reboot history ● last Linux file security  Every file is owned by a UID and a GID.
  • 28.  Every process runs as a UID and one or more GID’s. usually determined by who runs the process.  Three access categories.  Process running with the same UID as the file (user).  Process running with the same GID as the file (group).  All other process (other). What is Permission ?  Specifies what rights are you granting to users to access the resources are available in the computer, so that important resources such as files are protected from unauthorized users. Methods of Implementing Permissions  Symbolic Method  Numeric Method Applying Permission with Numeric Method 4. 4 (for read) 5. 2 (for write) 6. 1 (for execute) Example: - ~] # chmod 640 file name  If u wants to give the read, write, permission to owner then combined the both digit code (4+2=6), and read permission to group (4), and for other’s on permission then (0). chmod command is used to change access modes  Numeric Method ● chmod 664 somefile  file name (Grants Read and Write access to owner and group but read only it to and other. ) ● chmod 600 somefile  file name ( Sets read and write permission to owner, with execute turned off, with others and group have no permissions ) ● chmod 444 somefile  file name ( Make the file world-readable ) Umask  umask is a value which is subtracted from default to determine new file/ directory permissions  Default permission for files is 666  Default permission for directories is 777  Default Permission – Umask = Effective Permission ● Non-Privileged Users umask is 002  Files will have permissions of 664  Directories will have permission of 775 ● root’s umask is 022 ● Example :- ● 666 – 002 = 664 ● 666 – 244 = 422 ● 777 – 222 = 555 ● 777 – 027 = 750
  • 29. Special Permission for directories:  Sticky bit: the sticky bit for a directory sets a special restriction on deletion of files: with the sticky bit set, only the owner of the file and super user (root) can delete files within the directory. Sticky bit is (1) Example  ~] # chmod 1777 dirname  Sgid: files created in directories with the sgid bit set have group affiliations of the group the directory. (2) Example  ~] # chmod 2770 dirname  Often both the sticky bit and sgid permission will be set on a group directory. Example  ~] # chmod 3770 dirname  Example  ~] # chmod 4551 passwd Others do not have write- Others have readr Group has executex Group does not have write- Group has readr Owner has executex Owner has writew Others have execute Owner has readr x Permissions
  • 30. UNIT-16 The Linux File system in-Depth Basic File System Types  A file system is the logical structure and software routines that control access to the storage space on disks.  Unlike most operating systems, Linux supports several file system types.  The Ext2 (Second Extended) file system is the most common Linux file system and is the second version of the Ext file system  The Ext2 file system was designed to overcome deficiencies found in the Ext file system  The Ext file system can handle partitions up to 2 gigabytes (GB) in size, whereas Ext2 can handle partitions up to 4 terabytes (TB) in size Features of Ext2  The Ext2 file system has many other advanced features including provision for filenames up to 255 characters long  Ext2 also reserves disk space on the partition for the superuser. This means that if a disk develops a problem, the superuser can still access that disk and rectify it Ext3 file system  In Linux 7.2, ext2 is the default file system  Require check for consistency (e2fsck) when system is not properly shut down  Ext => ext2 =>ext3  Support 256 char filenames, 4 Tera byte max filesize  Others MS-Dos, FAT32, NTFS, ISO9660  Starting from Linux 7.3, ext3 is the default file system  Provide stronger data integrity in event of unclean shutdown  Check for consistency is needed only on rare hardware failure  Higher throughput, as it is optimizes hard drive head motion  Provide easy transition from ext2 to ext3  other common filesystem are MS-DOS (FAT32, NTFS, ISO9660)  The ext3 file system is essentially an enhanced version of the ext2 file system. Advantages are: Availability  After an power failure or system crash (also called an unclean system shutdown), each mounted ext2 file system on the machine must be checked for consistency by the e2fsck program. This is a time-consuming process that can delay system boot time significantly, especially with large volumes.  The journaling provided by the ext3 file system means that this sort of file system check is no longer necessary after an unclean system shutdown. The only time a consistency check occurs using ext3 is in certain rare hardware failure cases, such as hard drive failures. Data Integrity
  • 31.  The ext3 file system prevents loss of data integrity in the event that an unclean system shutdown occurs. The ext3 file system allows you to choose the type and level of protection that your data receives. Partition and File System  Disk drives are divided into partitions  Partition are formatted with file system, allows users to store data ● Default file system: ext3, the Third Extended Linux File System ● Other common file systems: ● ext2 and vfat ● iso9660 ( typically used for CDs) Links  A link is a file that points to another file.  “ln” creates a “link” from the original file to a new “file” in your directory.  Most programs will access the link as if it was the file.  This is similar to a “shortcut” in Windows.  This allows for aliasing (when two or more names can exist for the same object)  Easy way to point to a really long absolute pathname or filename Using Links  Two types of links can be created ● Symbolic ( Soft ) ● Hard ln -s main soft ( This will create an soft link of file “main” ) ln main hard ( This will create an hard link of file “main” ) Mounting the media  “Mounting” means making a partition to access from an access point typically a folder to store and access data from it. Commands to mount media mount /media/floppy = Mounts floppy drive to your computer mount /media/cdrom = Mounts cdrom drive to your computer mount /media/Device ID = Mounts usb disk to your computer Commands to unmount media umount /media/floppy = Unmounts floppy drive to your computer umount /media/cdrom = Unmounts cdrom drive to your computer umount /media/Device ID = Unmounts usb disk to your computer Archive Files  Archiving places many files into one target file  Easier to back up, store, and transfer  tar – Standard Linux archiving command Using Archive files – tar command  tar cvf archive_name files.. ( To create archive file )  tar tvf archive_name files..
  • 32. ( To display files under archive file )  tar xvf archive_name files.. ( To extract files from archive file )  tar rvf archive_name files.. ( To append archive file ) File Compression  Results in smaller file size  Text files can be compressed over 75%  tar archives are often compressed Compression Utilities  gzip, gunzip ● Standard Linux compression utility ● Up to 75% compression for text files  bzip2, bunzip2 ● Newer Linux compression utility ● Generally achieves better compression than gzip Using Compression  gzip somefile ( To create compressed file )  gunzip somefile ( To uncompress a compressed file )  bzip2 somefile ( To create compressed file )  bunzip2 somefile ( To uncompress a compressed file ) Note: - We can use z for gzip and j for bzip2 type of compression with tar UNIT-17 Essential System Administration Tools Red Hat Package Manager & Yum Server
  • 33. RPM:- The RPM Package manager greatly simplifies the distribution, installation, upgrading, and removal of software on Red Hat Enterprise Linux System. The local RPM database is maintained in /var/lib/rpm. The database stores information about installed packages such as file attributes and packages prerequisites. rpm is a backend for other programs such as yum or system-config-packages. The tools provide significant advantages such as automatic dependency resolution. Primary RPM options:-  rpm -I filename (for install)  rpm -U filename (upgrade)  rpm -F filename (for freshen)  rpm -e filename (for erase)  rpm -ivh filename (for update) Output Option:-  -v (Used for print package name)  -h (Used for print hash marks) RPM Queries:- RPM provide robust querying, which is invoked with rpm-q or rpmquery. Query option fall into one of two categories: those that specify which packages to query, and those that specify what information to retrieve. The first must be specified; the second defaults to the package name. Syntax: - rpm -qa |less rpm -qf filename (show owning package) rpm -qi package_name (general information) rpm -ql package_name (lists files in package) RPM Verification:- verifying an installed package compares the file sizes, permission, type, owner, group, MD5 checksum, and modify time against the RPM database. Any inconsistency will be reported. An installed package can also be verified against a package file as well: Syntax: - rpm -V zip verifies the installed zip rpm against the RPM database. rpm -Va verifies all installed RPMS against the RPM database. rpm -Vp zip-2.3-8.i386.rpm verifies the installed zip package against the zip pacakage file.