Post on 04-Jun-2018
8/13/2019 Unix 02
1/25
UNIX Day 2
Intermediate Level
8/13/2019 Unix 02
2/25
2
Recap Day 1
Introduction to UnixUnix System ArchitectureBasic Unix Commands
File and directory related commandsShell meta charactersStandard files
Redirection and Pipe
8/13/2019 Unix 02
3/25
3
Session Plan Day 2
Text Processing Commands
Process Related Commands
Memory Related CommandsCompression Utilities
8/13/2019 Unix 02
4/25
Text Processing Commands
8/13/2019 Unix 02
5/25
5
Command Description Syntax
paste Combines the content of the files
line by line Prints the files content horizontally
$ paste file1 [file2]
head Displays a set of lines of the given
data from start$ head [-n] file_name
tail Displays a set of lines of the givendata from last $ tail [ n/+n] file_name
wc Displays total no of lines, words andcharacters in any data $ wc [ lwc] file_name
Text Processing Commands (1/7)
8/13/2019 Unix 02
6/25
6
Command Description Syntax
tr Translate characters Used on output of some other
command
$ cmd_output | tr [option]src_charset tar_charset
Variations Syntax/Sample Example
Squeeze the character $ ls l | tr s
Squeeze and translate the characters $ ls l | tr s #
Translate the characters $ date | tr #
Text Processing Commands (2/7)
8/13/2019 Unix 02
7/257
Command Description Syntax
cut
Retrieves specific fields orcharacters from the data Used on output of some other
command or file content
$ cmd_output | cut[option] $ cut [option] file
Variations Syntax/Sample Example
Retrieve specific character set $ cat file1 | cut c5$ cat file1 | cut c5-10
Retrieves specific field set
$ date | cut d f3
$ date | cut d f3,5-d: for delimiter-f: for field number
Text Processing Commands (3/7)
8/13/2019 Unix 02
8/258
Command Description Syntax
sort
Used to order the data Used on output of some other
command or file content Default sorting is as per the
English dictionary
$ cmd_output | sort[option] $ sort [option] file
Variations Syntax/Sample Example
To sort in reverse order $ sort r file1
To remove duplicate data $ sort u file1
To apply numerical sort $ sort n file1
To merge the content of two or more files $ sort m file1 file2
Text Processing Commands (4/7)
8/13/2019 Unix 02
9/259
Command Description Syntax
grep Pattern search in the given data Global Regular Expression Parser $ grep [option] pattern data
Variations SyntaxIgnores case while searching $ grep i pattern file_namePrints only the count of the number of lines,having given pattern $ grep c pattern file_name
Prints the lines which are not containing
given pattern$ grep v pattern file_name
Text Processing Commands (5/7)
8/13/2019 Unix 02
10/2510
Matching for lines SyntaxPrints lines starting with any pattern $ grep ^pattern file_name
Prints lines ending with any pattern $ grep pattern$ file_name
Anchor Characters for grep Command
Matching for words Syntax
Defining the boundary of the words This will match only alphabetic and numeric characters
Prints the lines which are containing word
starting with any pattern$ grep \file_name
Prints the lines which are containing givenpattern as whole word $ grep \file_name
8/13/2019 Unix 02
11/25
11
Command Description Syntax
uniq Removes adjacent repeated lines inthe given data $ uniq [option] data
Variations SyntaxRemoves adjacent repeated lines and printsthe output $ uniq file_name
Prints only uniq lines $ uniq u file_name
Prints only duplicate lines $ uniq d file_name
Text Processing Commands (6/7)
8/13/2019 Unix 02
12/25
12
Command Description Syntax
cmp Used to compare two files Pinpoints only the first difference
between two files$ cmp file1 file2
comm
Used to compare two files Can be applied only on sorted
files Give the result in three columns:
First column: Data unique to firstfileSecond column: Data unique to
second fileThird column: Data common inboth the files
$ comm file1 file2
Text Processing Commands (7/7)
8/13/2019 Unix 02
13/25
13
Self Study: Text ProcessingCommands Demo
8/13/2019 Unix 02
14/25
14
Can you answer these questions?
What should be the command:To count the number of directories and filespresent in the current working directoryTo count the number of blank lines (lines without
text) in a fileTo display the first 8 lines from a fileTo display only the 4 th line from a file
Differentiate betweencat file1 file2 file3 & paste file1 file2 file3
8/13/2019 Unix 02
15/25
Process and Memory relatedCommands
8/13/2019 Unix 02
16/25
16
Process related Commands
A process is a program in execution
Each process is allocated a process identifier
or PID
In general, each process is started by another,
known as parent process.
So every process is also have one parentprocess identifier or PPID
8/13/2019 Unix 02
17/25
8/13/2019 Unix 02
18/25
18
Command Description Syntax & important variations
nice Execute a command withupdated scheduling priority $ nice [option] [command]
nohup
Executes the command in
background even after log outfrom the session $ nohup command
kill Used to send a signal to aparticular process$ kill [signal_info] PID$ kill [signal_info] %JobID
Process related Commands (2/2)
8/13/2019 Unix 02
19/25
19
Command Description Syntax & important variations
df Prints file system disk spaceusage $ df [FILE]
du Estimates file space use $ du [FILE]
Memory related Commands
df command du commandIt will display the information about theblocks of different file systems installed
on our system.ORIt will give the information about inwhich particular file system thespecified file or directory is available.
It will display the block used by all thedirectories and sub-directories availableunder the present working directory.ORIt will display the block used by thespecified file or directory.
8/13/2019 Unix 02
20/25
Compression Utilities
8/13/2019 Unix 02
21/25
lf d l
8/13/2019 Unix 02
22/25
22
Self Study: Compression UtilitiesDemo
8/13/2019 Unix 02
23/25
23
Can you answer these questions?
Differentiate between bg and fg commands.Differentiate between df and du commands.Harry has a directory named Dir1 containing 872files. James wants to use Dir1. How will Harry sendthis through mail to James?
8/13/2019 Unix 02
24/25
24
Summary
Text Processing Commands.Process related CommandsMemory related CommandsCompression Commands
8/13/2019 Unix 02
25/25
2525
Thank You