0% found this document useful (0 votes)
9 views59 pages

UNIT 9(Commands Set2)

Uploaded by

vegow58383
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views59 pages

UNIT 9(Commands Set2)

Uploaded by

vegow58383
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 59

wc Command

• It s used to find out number of newline count, word count, byte

and characters count in a files specified by the file arguments. ▪


Syntax :
wc [options] filenames
Optio Use
n wc -l Prints the number of lines in a file

wc -w Prints the number of words in a file


wc -c Displays the count of bytes in a file
wc -L Prints only the length of the longest line in a file

121
wc Command Example

wc -L Prints only the length of the longest line in a file

122

wc Command Example
wc -l Prints the number of lines in a file
wc -w Prints the number of words in a file
wc -c Displays the count of bytes in a file

123

ln Command
• ln creates links between files.
• ln creates hard links by default, or symbolic links if the -s (--
symbolic) option is specified. When creating hard links, each
TARGET must exist.

▪ Syntax :
ln [OPTION]… [-T] TARGET LINK_NAME
Optio Use
n ln -f If the destination file or files already exist, overwrite them

ln -i Prompt the user before overwriting destination files


ln -s Make symbolic links instead of hard links

124

ln Command Example
125

ln Command Example
ln -s Make symbolic links instead of hard links
f2.txt f6.txt
(hello good morning) (hello good morning)
126

nl Command
• nl command numbers the lines in a file.
▪ Syntax :
nl [OPTION]... [FILE]...

▪ Example :
Optio Use
n nl -i Line number increment at each line

nl -s Add STRING after (possible) line number


nl -w Use NUMBER columns for line numbers

127

nl Command Example
128

nl Command Example
nl -i Line number increment at each line
129

nl Command Example
nl -s Add STRING after (possible) line number
130

nl Command Example
nl -w Use NUMBER columns for line numbers

131
head Command
• head makes it easy to output the first part (10 lines by default) of
files.

▪ Syntax :
head [OPTION]... [FILE]...

▪ Example :
Optio Use
Print the first n lines instead of the first 10; with the leading '-',
n print all but the last n lines of each file
head -
n
head -c Print the first n bytes of each file; with a leading '-', print all but
the last n bytes of each file
head -q Never print headers identifying file names

132

head Command Example


133

head Command Example


head -n Print the first n lines instead of the first 10; with the leading '-',
print all but the last n lines of each file
134

head Command Example


head -c Print the first n bytes of each file; with a leading '-', print all but
the last n bytes of each file

135
head Command Example
head -q Never print headers identifying file names

136
tail Command
• tail is a command which prints the last few number of lines (10
lines by default) of a certain file, then terminates.

▪ Syntax :
tail [OPTION]... [FILE]...
Optio Use
n tail - Output the last num lines, instead of the default (10)
n
tail -c Output the last num bytes of each file
tail -q Never output headers

137
tail Command Example

138

tail Command Example


tail -n Output the last num lines, instead of the default (10)

139

tail Command Example


tail -c Output the last num bytes of each file
140

sort Command
• sort command is used to sort a file, arranging the records in a
particular order.
• By default, the sort command sorts file assuming the contents are
ASCII. Using options in sort command, it can also be used to sort
numerically.

▪ Syntax : sort [OPTION]... [FILE]...


Option Use
sort -c To check if the file given is already sorted or not
sort -r Reverse the result of comparisons
sort -n Compare according to string numerical value
sort -nr To sort a file with numeric data in reverse order
sort -k Sorting a table on the basis of any column
sort -b Ignore leading blanks

141

sort Command Example


142

sort Command Example


sort -c To check if the file given is already sorted or not
143

sort Command Example


sort -r Reverse the result of comparisons
144

sort Command Example


sort -n Compare according to string numerical value
sort -nr To sort a file with numeric data in reverse order
145

sort Command Example


sort -k Sorting a table on the basis of any column
146

find Command
• find command searches for files in a directory hierarchy.

▪ Syntax :
find [option] [path...] [expression]
Option Use
find -name filename Search for files that are specified by ‘filename’
find -newer filename Search for files that were modified/created after
‘filename’
find -user name Search for files owned by user name or ID ‘name’
find -size +N/-N Search for files of ‘N’ blocks; ‘N’ followed by ‘c’ can
be used to measure size in characters
find -empty Search for empty files and directories
find -perm octal Search for the file if permission is ‘octal’

147

find Command Example


148

find Command Example


find -newer filename Search for files that were modified/created after
‘filename’
149

find Command Example


find -user name Search for files owned by user name or ID ‘name’
150

find Command Example


find -size +N/-N Search for files of ‘N’ blocks; ‘N’ followed by ‘c’
can be used to measure size in characters
151

find Command Example


find -empty Search for empty files and directories
152

uniq Command
• uniq reports or filters out repeated lines in a file.
• It can remove duplicates, show a count of occurrences, show only
repeated lines, ignore certain characters and compare on specific
fields.

▪ Syntax :
uniq [OPTION]... [INPUT [OUTPUT]]
Optio Use
n uniq Prints only unique lines
-u
uniq -d Only print duplicated lines
uniq -D Print all duplicate lines
uniq -c Prefix lines with a number representing how many times they
occurred
uniq -i Ignore case when comparing

153

uniq Command Example


154

uniq Command Example


uniq -u Prints only unique lines
155

uniq Command Example


uniq -d Only print duplicated lines
156

grep Command
• The grep filter searches a file for a particular pattern of characters,
and displays all lines that contain that pattern.
• The pattern that is searched in the file is referred to as the regular
expression.
• grep stands for globally search for regular expression and print out.

▪ Syntax :
grep [options] pattern [files]
Optio Use
n grep Prints only a count of the lines that match a pattern
-c
grep -h Display the matched lines, but do not display the filenames
grep -l Displays list of a filenames only
grep -i Ignores, case for matching

157

grep Command Example


158

grep Command Example


grep -c Prints only a count of the lines that match a pattern
grep -h Display the matched lines, but do not display the filenames
grep -l Displays list of a filenames only
159

grep Command Example


grep -n Display the matched lines and their line numbers
160

grep Command Example


grep -v This prints out all the lines that do not matches the pattern
161

grep Command Example


grep -w Match whole word
162

grep Command Example


grep -o Print only the matched parts of a matching line
163

grep Command Example


164

pipe (|) Command


• It redirects the command STDOUT or standard output into the
given next command STDIN or standard input.
• In short, the output of each process directly as input to the next
one like a pipeline.
• The symbol '|' denotes a pipe.
• Pipes help you mash-up two or more commands at the same time
and run them consecutively.

▪ Syntax :
command_1 | command_2 | command_3 | .... | command_N…

165

pipe Command Example


166

pipe Command Example


167

pipe Command Example


168

tr(translate) Command
• The tr command in UNIX is a command line utility for translating or
deleting characters.
• It supports a range of transformations including uppercase to
lowercase, squeezing repeating characters, deleting specific
characters and basic find and replace.
• It can be used with UNIX pipes to support more complex
translation.
• tr stands for translate.

▪ Syntax :
tr [OPTION] SET1 [SET2]

169

tr(translate) Command
▪ POSIX Character set supported by tr command :
• [:digit:] Only the digits 0 to 9.
• [:alnum:] Any alphanumeric character.
• [:alpha:] Any alpha character A to Z or a to z.
• [:blank:] Space and TAB characters only.
• [:xdigit:] Hexadecimal notation 0-9, A-F, a-f.
• [:upper:] Any alpha character A to Z.
• [:lower:] Any alpha character a to z..
Option Use
tr -s Replaces repeated characters listed in the set1 with single occurrence
tr -d Delete characters in string1 from the input
tr -c complements the set of characters in string. i.e., operations apply to
characters not in the given set
tr -cd Remove all characters except digits

170

tr Command Example
171

tr Command Example
172

tr Command Example
tr -s Replaces repeated characters listed in the set1 with single occurrence
173

tr Command Example
tr -d Delete characters in string1 from the input

174

tr Command Example
tr -c complements the set of characters in string.
i.e., operations apply to characters not in the given set
175

tr Command Example
tr -cd Remove all characters except digits

176
history Command
• history command is used to view the previously executed
command.

▪ Syntax :
history

▪ Example :
177

history Command Example

178
write Command
• write sends a message to another user.

▪ Syntax :
write user [ttyname]

▪ Example
Optio Use
n user The user to write to

tty The specific terminal to write to, if the user is logged in to more
than one session

179

write Command Example


• Open first terminal.

• Open Second terminal then execute command on first terminal.

180

wall Command
• wall send a message to everybody’s terminal.
• wall sends a message to everybody logged in with their mesg
permission set to yes.

▪ Syntax :
wall [-n] [-t TIMEOUT] [file]

▪ Example
Optio Use
n wall --nobanner Suppress banner
-n
wall -t --timeout TIMEOUT Write timeout to terminals in seconds.
TIMEOUT must be positive integer. Default value is 300 seconds,
which is a legacy from time when people ran terminals over
wall Command Example
• Open four different terminal, execute command on first terminal, message will display on
everybody’s terminal.
182

You might also like