‘Find’ is very power full tool that we can use in Linux terminal as a searching tool. ‘Find’ searches the directory tree rooted at each given file name by evaluating the given expression from left to right, according to the rules of precedence, until the outcome is known , at which point find moves on to the next file name.
SYNOPSIS
EXAMPLESfind [path...] [expression]
Name, user and location related searching
Code: Select all
find / -name hello
Code: Select all
find / -iname hello
Code: Select all
find /home -name *ello
Code: Select all
find /home -user udithaM
This will list down the files which own by the user inside the /home directory
Code: Select all
find $HOME -mtime 0
This will list down the file which are modified within the last 24 hrs inside the /home directory.
Other options can use with time:
-amin n File was last accessed n minutes ago.
-cmin n File's status was last changed n minutes ago.
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.
-ctime n
File's status was last changed n*24 hours ago. This option can be used as above
Eg :
Find every file under the directory /etc that was modified more than 20 days ago.
Code: Select all
find /etc -mtime +20
How do i find file containing ‘Colombo’. So that i can use it to change the timezone.
Code: Select all
grep -irn ‘colombo’ /etc
Searching can be performed according to type such as file, directory, link.
-type f - for file seraching
d - for directory seraching
l - for link searching
Eg :
Searching file name timezone inside the /etc folder
Code: Select all
find / -type f -name -i TIMEZONE
Identify the difference between these two
Code: Select all
find /tmp -name udithaM -type f -print | xargs /bin/rm -f
Code: Select all
find /tmp -name udithaM -type f -print0 | xargs /bin/rm -f