WarpZero RSS WarpZero@Twitter WarpZero@LinkedIn Michael Marth@Facebook Monday, 21-May-2012 01:51:38 EDT
   
warpzero.com

° Home
° News & Updates
° Howto & Knowledge Base
° External Resources
° Contact us
° Search
° Site Validated
° Site Map




Use find to locate files that do not match pattern




This document should help provide the necessary information to find specific files that do not match based on user / group and permissions on a linux or unix system.




  1. Replace the parameters in bold with your criteria.
    Note the trailing semi-colon ";" after the slash "\" slash and yes there is a space after the last curly bracket "}"

    find /directory -type file/directory type ! \( -user user -a -group group -a -perm permission \) -ls

  2. Example: Search for file types within the /testing directory that don't have an owner of nobody, group of staff and permission of 555. Files not matching this criteria would be displayed.

    find /testing -type f ! \( -user operator -a -group nobody -a -perm 555 \) -ls

    Results are as follows:

    BEFORE: Contents of the entire directory
    ls -al /testing/
    drwxr-xr-x  3 root     root      4096 2010-08-10 14:41 .
    drwxr-xr-x 26 root     root      4096 2010-08-10 13:53 ..
    -rw-------  1 root     root      5017 2010-08-10 13:53 access.log
    -r-xr-xr-x  1 operator nobody   11383 2010-08-10 14:41 alert.log
    -rwx---r--  1 operator nobody    6315 2010-08-10 14:39 dummy_file1.txt
    -rw-------  1 root     root      5296 2010-08-10 14:39 dummy_file2.txt
    -r-xr-xr-x  1 operator nobody    5068 2010-08-10 14:39 dummy_file3.txt
    -rw-rw----  1 root     root   1140632 2010-08-10 13:53 errors
    -rw-------  1 root     root   6950126 2010-08-10 13:53 security.log
    dr-xr-xr-x  2 operator nobody    4096 2010-08-10 14:40 testing2
    

    AFTER: display after execution of example command
    find /testing -type f ! \( -user operator -a -group nobody -a -perm 555 \) -ls
    310697 6800 -rw-------   1 root     root      6950126 Aug 10 13:53 /testing/security.log
    310699    8 -rw-------   1 root     root         5296 Aug 10 14:39 /testing/dummy_file2.txt
    310695    8 -rw-------   1 root     root         5017 Aug 10 13:53 /testing/access.log
    310698    8 -rwx---r--   1 operator nobody       6315 Aug 10 14:39 /testing/dummy_file1.txt
    310696 1120 -rw-rw----   1 root     root      1140632 Aug 10 13:53 /testing/errors
    

    NOTE: the below files were not displayed as they contained the matching user/group and permission set. The directory was also not displayed as it did not match the "file" criteria.
    -r-xr-xr-x  1 operator nobody   11383 2010-08-10 14:41 alert.log
    -r-xr-xr-x  1 operator nobody    5068 2010-08-10 14:39 dummy_file3.txt
    dr-xr-xr-x  2 operator nobody    4096 2010-08-10 14:40 testing2
    

Linux Counter
Apache
IBM Canada
Cisco Systems
RedHat
Linux
 
 Published: Wednesday, 10-Nov-2010 05:16:58 EST