Finding Files and Directories

finding files and directories

Find command searches for files and directories as per the defined criteria.

find command also searches inside the sub-dir of specified path.

Syntax:

find [path] <criteria> <action>

path=where to search

Criteria can be:

-name <filename>   [name based search]

-iname <filename> [name based search, but ignorecase]

-perm <perm>                       [permission ,,     ,, ]

-atime -N,+N,N                      [access time ,, ,,]

-mtime -N,+N,N                     [modified  ,,  ,,]

-user <user>             [modified ,,  ,,]

-group <group>                    [group ownership based search]

-size <size>               [size based search eg. 20M,20K or give 20c to treat size as character].

-type                           [type can be f d c b etc]

eg.

#find / -name passwd   (/ is before root) (it searches all the files of passwd inside the /)

#find / -perm 660

#find -mtime 3 (it searches before 3 days file)

Processing the find files:

-exec (doesn’t give interactive message)

-ok       (Interactively)

{}          place holder for found files.

eg.

#find / -name groub.conf -and -user root -ok cp {} /test11 \;   (termination of command)

Slocate/Locate:-

Slocate and locate commands searches for files and directories in the updated database. The files and directories matching the pattern are returned.

-By default system updates the database in every 24 hours (eg. a daily task)

Syntax:

locate/slocate pattern

#slocate httpd.conf (locates httpd.conf from our system)

#slocate hosts.allow

#updatedb (updates the slocate database)