In this above command, you will get all bad pattern present
inside the file.
Q) How many only bad pattern present inside the above file
FileSample.txt ?
Ans - $ grep –ow bad FileSample.txt | wc
–l<Enter – Key>
Q) How to get 2 lines present after the pattern line ?
Ans - $ grep –A <Number of Lines present
after the pattern line> <Pattern> <File Name><Enter – Key>
Q) How to get 2 lines present before the pattern line ?
Ans - $ grep –B <Number of Lines present
before the pattern line> <Pattern> <File Name><Enter –
Key>
Q) How to get 3 lines present before or after the pattern
line ?
Ans - $ grep –C <Number of Lines present
before or after the pattern line> <Pattern> <File Name><Enter
– Key>
Q) How you search multiple patterns in a file ?
Ans – For Multiple Pattern Search, we go for egrep or
extended grep.
Example –
$ grep –e bad –e good FileSample.txt<Enter –
Key>
Here you will get bad and good pattern along with only bad
and good pattern.
$ egrep ‘bad | good’ FileSample.txt<Enter –
Key>
Here you will get only bad and good pattern.
$ grep –E ‘bad | good’ FileSample.txt<Enter –
Key>
Here you will get only bad and good pattern.
Q) How you get lines having more than five or seven patterns
from a file ?
Ans – Here we will go for fgrep i.e. file grep.
Put all the patterns in one file line by line.
Then run the below command.
$ fgrep <Multiple Pattern Containing File Name>
<File Name><Enter – Key>
Stat Command: -
Q) Which command will show the creation, modification and
access time, inode number and number of links of a file ?
Ans - $ stat <File Name><Enter – Key>
Man Command: -
Q) How you show a particular command details related to its
working description, option deatils etc ?
Ans - $ man <Command Name><Enter – Key>
Tac Command: -
Q) Which command will show a file content in reverse order
i.e. last line of the file will be first line, then 2nd last line
will be 2nd line and so on ?
Ans - $ tac <File Name><Enter – Key>










No comments:
Post a Comment