Line pattern

Line pattern in Unix

Anchors:         ˄          Þ        start of the line.

$          Þ        End of the line .

$grep “˄d”      sample                        line start with d

$grep “˄me”   sample                        line start with me.

$grep “me$”   sample                        line end with me

$grep “˄[˄aei]            sample                        Not start with a,e,i

$grep   “[0-9]$” sample          line ending with digit

$grep   “˄unix$” sample        line should contain only unix

$grep   “˄$”     sample           displays empty lines

$grep   “˄…..$” sample           line should contain three characters


Fgrep:  To search the string more faster than the grep command

$fgrep “unix


>dba”  sample

Egrep (extended grep): It is a combination of grep & fgrep plus some additional regular expressions.

$egrep “(unix/oracle/sas)”     sample

$ egrep ab{3}c sample                        Exact occurrence of preceding character

$egrep “\<[0-9] {4,7}/>” sample

$egrep             ab{3} c Þ        abc                  abbbc              abbbbbc

O                     P                     O

Þ Find: This filter is used to search the results by depending on requirements may be on name,inode, permissions, user ………..etc.

Syn:     Find <search path> <criteria> <action>

(a)        Based on name:

$find   /          -name passwd

$find   /home -name passwd

$find   /etc     -name ‘pass*’

$find   .           -name linux

(b)   Based on size:

+n        Þ  for greater than n.

-n         Þ for less than n.

N        Þ for exactly n.

$ find /            -size     4c                    4 character files

$ find / -size   +4c                  More than 4 character files

$find /-size     -4c                   less than 4 characters

$find.-size       +50M               More than 50M

$find   /etc/backup    -size     -50M               less than 50m

$find   / -size    +30M -size     -50M               Between 30 to 50M


(c) Based on permissions:

$find   /          -perm  644

$find   /          -perm  665

$find   /          -perm  777

(d) Based on Type:

$find   /          -type   f                       To find files

$find   /          -type   d                      to find directories


(e) Based on inode:

$ find  /          -inum  15253

$ find  / root  -inum  32512

$ find  / home –inum            130123


(f) Based on time:

M time à Modification time.

C time à change time.

A time à Access time.

$ find / -m time          +10

$ find / -m time          -10

$find / -m time             10

Learn more about Linux Interview Questions in this blog post. Interested in mastering Linux ? Check out this blog post to learn more Linux Training Videos

  • To find the file with access time:

$find   / root  -a time                        +5                    5 days ago

$find   / root -a time                        -5

$ find  / root  -a time                          5


  • To find the file with change time:

$ find  /          -c time             +5

“                       “                -5

“                       “                   5

$find   /          -amin +5               File was last accessed 5 minutes ago

$find   / root  -cmin   +5               File’s status was last change 5 minutes ago

$find   / home            -m min+5

$find   .           -amin  5


(g) Based on user:

$ find /                        -user    <username>

$ find /                        -user raju                    particular user files.

(h) Based on group

$find   /          group  <group name>

$find   /          group sales                 Particular group files.

*Path: It is the way of representing files & directories in the system

  • There are two types of paths.
  • Absolute path: It is the way of representing files and directories from the top of hierarchy

EX:      $ls  /root/world/asia/india/ap/hyd/

$cp  /home/raju/linux/root/world/asia

(ii) Relative path: It is the way of representing files and directories which are related to current directory.

EX:  $cd /home/raju/desktop

$cp      linux    unix/SQS

$cd      unix/sas


For indepth understanding of Linux click on