Monday, 14 December 2015

Search Files Based On MULTIPLE Criteria In Unix/Linux

In this article, We will see how find search the files based on multiple criteria. like
1. file whose permissions are 777 and not accessed since last 7 days.
2. file whose size is 20MB and not accessed since 20 days and so on.
Before you start this article please go through the following articles, if you have already not followed.


Search Files Based On MODIFIED Time In Unix/Linux
Search Files Based On ACCESS Time In Unix/Linux
Search Files Based On CHNAEGED Time In Unix/Linux
Search Files Based On PERMISSION In Unix/Linux
Search Files Based On SIZE In Unix/Linux

Files having permission as 777 and not accessed since last 7 days.
$ find . -perm 777 -atime +7
$ find . -perm 777 -mtime +7
$ find . -perm 777 -ctime +7

Output: Will return all the files which are having permission as 777 and not accessed/modified/changed more than 7 days.
Note: We can change the values of -perm & -atime/mtime/ctime to achieve the required.

Files having permission as 777 and of size greater/less than 10 MB.
$ find . -perm 777 -size +10M
$ find . -perm 777 -size -10M

Output: Will return all the files which are having permission as 777 and of size greater/less than 10 MB.

Files having permission 777, less than 10MB and have not accessed more than 7 days.
$ find . -perm 777 -size -10M -atime +7

Conclusion:
As explained above we can use the find command switches (-perm/-atime/-mtime/-ctime/-size and so on.) to perform complex searches in single line. Practice will take you to the heights so keep practicing and enjoy the FIND...!!!!


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...