More Related Content
Similar to 03 t1 s2_linux_lesson3
Similar to 03 t1 s2_linux_lesson3 (20)
03 t1 s2_linux_lesson3
- 1. Managing Documents
Objectives
In this lesson, you will learn to:
Identify the standard input, output, and error files
Use input, output, and error redirection
Identify the features and options of the grep, wc, cut,
and tr filters
Combine multiple commands by using Pipes
Locate a file by using the find command
Assign File Access Permissions (FAPs)
©NIIT Linux/Lesson 2/Slide 1 of 20
- 2. Managing Documents
Standard Files
Standard Input File
The keyboard is referred to as the standard input
file
In Linux, all the open files, including the standard
files, are assigned a number called the file
descriptor. The file descriptor 0 is assigned to the
standard input file
Standard Output File
The monitor is referred to as the standard output
file
The file descriptor 1 is assigned to the standard
output file
©NIIT Linux/Lesson 2/Slide 2 of 20
- 3. Managing Documents
Standard Files (contd)
Standard Error File
The monitor is also the standard error file
The file descriptor 2 is assigned to the standard
error file
©NIIT Linux/Lesson 2/Slide 3 of 20
- 4. Managing Documents
Redirection
Redirection changes the assignments for the standard
input, output, and error
Input Redirection
The following example illustrates the use of input
redirection:
$ cat test1 Enter
Output Redirection
The following example illustrates the use of output
redirection:
$ cat test1 test2
©NIIT Linux/Lesson 2/Slide 4 of 20
- 6. Managing Documents
Filters
A filter is a program that takes its input from the standard
input file, processes (or filters) it, and sends its output to
the standard output file
The grep Filter
The grep filter searches a file for a particular pattern
of characters and displays all the lines that contain
that pattern. The pattern that is searched for is
referred to as a regular expression
grep regular_expression [filename]
©NIIT Linux/Lesson 2/Slide 6 of 20
- 7. Managing Documents
Filters (contd.)
The grep Filter (contd.)
Options of the grep Filter
-n : This prints each line matching the pattern
along with its line number
-c : This prints only a count of the lines that
match a pattern
-v : This prints all the lines that do not match the
pattern specified by the regular expression
©NIIT Linux/Lesson 2/Slide 7 of 20
- 8. Managing Documents
Filters (contd.)
The wc Filter
The wc filter is used to count the number of lines,
words, and characters in a disk file or in the
standard input
wc [-lwc] [filename/s ]
The cut Filter
The cut filter is useful when specific columns from
the output of certain commands (such as ls, who)
need to be extracted
cut [options] [filename/s]
©NIIT Linux/Lesson 2/Slide 8 of 20
- 9. Managing Documents
Filters (contd.)
The tr Filter
The tr filter can be used to translate one set of
characters to another
$ tr ':' ' ' /etc/passwd
©NIIT Linux/Lesson 2/Slide 9 of 20
- 10. Managing Documents
Just a Minute…
The details of various customers who have
registered with Diaz Telecommunications are
stored in the Customers file. The sample data of
the file is as follows:
000001,Angela,Smith,16223
Radiance Court,Kansas
City,Kansas
000002,Barbara,Johnson,227
Beach Ave.,Alexandria,Virginia
000003,Betty,Williams,1 Tread
Road,Dublin,Georgia
©NIIT Linux/Lesson 2/Slide 10 of 20
- 11. Managing Documents
Just a Minute…(contd.)
Write a command to find the number of people
staying in the state of Kansas
Write a command to display the complete details
along with the line number in which the details are
present for the customer Linda
©NIIT Linux/Lesson 2/Slide 11 of 20
- 12. Managing Documents
Pipes
The vertical bar (|) is the pipe character
It indicates to the shell that the output of the command
before ‘|’ is to be sent as input to the command after
‘|’
The tee Command
The tee command takes standard input and writes
to standard output to file(s)
If the file where data is to be written does not exist,
the file is created
If the file already exists, its contents are
overwritten
cat temp | tee temp1 temp2
©NIIT Linux/Lesson 2/Slide 12 of 20
- 13. Managing Documents
Just a Minute…
The details of various customers who have
registered with Diaz Telecommunications are
stored in the Customers file. Sample data from the
file is as follows:
000001,Angela,Smith,16223
Radiance Court,Kansas
City,Kansas
000002,Barbara,Johnson,227
Beach Ave.,Alexandria,Virginia
000003,Betty,Williams,1 Tread
Road,Dublin,Georgia
©NIIT Linux/Lesson 2/Slide 13 of 20
- 14. Managing Documents
Just a Minute…(contd.)
In the file, the field delimiter is ','. The various fields
are CustomerCode, FirstName, LastName,
Address, City, and State. Write a command to
display only the FirstName and the LastName of
the customers living in Georgia
©NIIT Linux/Lesson 2/Slide 14 of 20
- 15. Managing Documents
Locating Files in Linux
The find Command
find [path] [expression]
The find command is used to locate a file in a
particular directory and in all its subdirectories. It is
the most commonly used command for locating
files and has various options for advanced
searches
©NIIT Linux/Lesson 2/Slide 15 of 20
- 16. Managing Documents
File Access Permissions (FAPs)
File Access Permissions (FAPs) refer to the
permissions associated with a file with respect to the
following:
The file owner
The group owner
Other users
©NIIT Linux/Lesson 2/Slide 16 of 20
- 17. Managing Documents
Assigning Permissions to Files
The chmod command
chmod mode file/s
The chmod command is used to change the
permissions associated with a file or a directory.
There are two modes for assigning the
permissions:
• Symbolic mode – the permissions and the type of
users for whom the permission is to be granted are
given in symbols.
• Absolute mode – In this, a series of digits is used
to represent the actual permissions.
©NIIT Linux/Lesson 2/Slide 17 of 20
- 18. Managing Documents
Summary
In this lesson, you learned that:
You can redirect input, output, and errors to a file
other than the standard files by the file descriptors
along with the redirection symbols, and
The output and error(s) of a command can be
appended to another file using the symbol
The grep filter searches the standard input or a file
for a particular pattern of characters, and displays all
lines that contain that pattern
The wc filter counts the number of lines, words, and
characters in a disk file or in the standard input
©NIIT Linux/Lesson 2/Slide 18 of 20
- 19. Managing Documents
Summary (contd.)
The cut filter is used when specific columns from the
output of certain commands (or files) need to be
extracted
The tr filter is used to translate one set of characters
to another
A pipe is a feature through which the standard output
of a command or user program can be sent as the
standard input to another command or user program
The tee command takes standard input and writes to
standard output and to file(s)
©NIIT Linux/Lesson 2/Slide 19 of 20