Sie sind auf Seite 1von 25

UNIX Day 2

Intermediate Level

Recap Day 1
Introduction to Unix Unix System Architecture Basic Unix Commands File and directory related commands Shell meta characters Standard files Redirection and Pipe

Session Plan Day 2


Text Processing Commands
Process Related Commands

Memory Related Commands


Compression Utilities

Text Processing Commands

Text Processing Commands (1/7)


Command Description paste
Combines the content of the files line by line Prints the files content horizontally Displays a set of lines of the given data from start Displays a set of lines of the given data from last

Syntax $ paste file1 [file2]

head
tail wc

$ head [-n] file_name


$ tail [n/+n] file_name

Displays total no of lines, words and $ wc [lwc] file_name characters in any data

Text Processing Commands (2/7)


Command Description tr
Translate characters Used on output of some other command

Syntax $ cmd_output | tr [option] src_charset tar_charset Syntax/Sample Example $ ls l | tr s $ ls l | tr s # $ date | tr #

Variations
Squeeze the character Squeeze and translate the characters Translate the characters

Text Processing Commands (3/7)


Command Description cut
Retrieves specific fields or characters from the data Used on output of some other command or file content

Syntax $ cmd_output | cut [option] $ cut [option] file Syntax/Sample Example $ cat file1 | cut c5 $ cat file1 | cut c5-10 $ date | cut d f3 $ date | cut d f3,5 -d: for delimiter -f: for field number

Variations
Retrieve specific character set

Retrieves specific field set

Text Processing Commands (4/7)


Command Description
Used to order the data Used on output of some other command or file content Default sorting is as per the English dictionary

Syntax

sort

$ cmd_output | sort [option] $ sort [option] file Syntax/Sample Example


$ sort r file1 $ sort u file1

Variations
To sort in reverse order To remove duplicate data To apply numerical sort To merge the content of two or more files

$ sort n file1
$ sort m file1 file2

Text Processing Commands (5/7)


Command Description grep Syntax

Pattern search in the given data $ grep [option] pattern data Global Regular Expression Parser

Variations
Ignores case while searching Prints only the count of the number of lines, having given pattern Prints the lines which are not containing given pattern

Syntax $ grep i pattern file_name $ grep c pattern file_name $ grep v pattern file_name

Anchor Characters for grep Command


Matching for lines
Prints lines starting with any pattern
Prints lines ending with any pattern

Syntax

$ grep ^pattern file_name


$ grep pattern$ file_name

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 Prints the lines which are containing word ending with any pattern Prints the lines which are containing given pattern as whole word

$ grep \<pattern file_name


$ grep pattern\> file_name $ grep \<pattern\> file_name

10

Text Processing Commands (6/7)


Command Description uniq Syntax

Removes adjacent repeated lines in $ uniq [option] data the given data

Variations

Syntax

Removes adjacent repeated lines and prints $ uniq file_name the output
Prints only uniq lines Prints only duplicate lines

$ uniq u file_name $ uniq d file_name

11

Text Processing Commands (7/7)


Command Description cmp
Used to compare two files Pinpoints only the first difference between two files Used to compare two files Can be applied only on sorted files Give the result in three columns: First column: Data unique to first file Second column: Data unique to second file Third column: Data common in both the files

Syntax $ cmp file1 file2

comm

$ comm file1 file2

12

Self Study: Text Processing Commands Demo

13

Can you answer these questions?


What should be the command:
To count the number of directories and files present in the current working directory To count the number of blank lines (lines without text) in a file To display the first 8 lines from a file To display only the 4th line from a file

Differentiate between
cat file1 file2 file3 & paste file1 file2 file3

14

Process and Memory related Commands

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 parent process identifier or PPID
16

Process related Commands (1/2)


Command Description
Displays the list of processes submitted to kernel Used to see the status of background jobs Used to bring any background job in foreground

Syntax & important variations


$ ps $ ps f :Full Listing showing PPID $ ps e :Including user and system processes $ bg $ fg %JobID OR fg #PID

ps

bg fg

17

Process related Commands (2/2)


Command Description
nice nohup
Execute a command with updated scheduling priority Executes the command in background even after log out from the session Used to send a signal to a particular process

Syntax & important variations


$ nice [option] [command] $ nohup command $ kill [signal_info] PID $ kill [signal_info] %JobID

kill

18

Memory related Commands


Command Description df du
Prints file system disk space usage Estimates file space use

Syntax & important variations $ df [FILE] $ du [FILE]

df command
It will display the information about the blocks of different file systems installed on our system. OR It will give the information about in which particular file system the specified file or directory is available.
19

du command
It will display the block used by all the directories and sub-directories available under the present working directory. OR It will display the block used by the specified file or directory.

Compression Utilities

Compression Utilities
Command Description Utility for compression and gzip
decompression of files Compressed files have .gz extension Used to view the content of compressed file Used to view the content of compressed file pagewise Utility for decompression of files having extension .gz Same as gzip d Creates a tape archive file Extracts from archive file

Syntax $ gzip file1 [file2] $ gzip d file1.gz $ zcat file1.gz

zcat

zmore
gunzip tar

$ zmore file1.gz
$ gunzip file1.gz $ tar -cvf file1.tar file1 $ tar -xvf file1.tar

21

Self Study: Compression Utilities Demo

22

Can you answer these questions?


Differentiate between bg and fg commands. Differentiate between df and du commands. Harry has a directory named Dir1 containing 872 files. James wants to use Dir1. How will Harry send this through mail to James?

23

Summary
Text Processing Commands. Process related Commands Memory related Commands Compression Commands

24

Thank You

25