Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    173
    Provided Answers: 1

    Question Unanswered: Stop unix find command from reading or trying to read: sub-directories

    How do you tell the find command to NOT read sub-directories ( or from trying to ) when searching for a file?

    /tmp directory list:
    -rw-rw-r-- 1 brown dev 0 Jan 31 08:46 bar_1.txt
    drwx------ 2 root root 182 Feb 23 16:50 smc898
    drwx------ 2 webadmin webadmin 422 Feb 23 16:51 https-fpdbtst1.fuelman.com-ab0d7966
    drwxr----- 2 oracle dba 179 May 17 12:26 hsperfdata_oracle


    It is correctly finding the file and the messages about trying to access the sub-directories are not a big deal because I've got them going to a log file but I know there has got to be a way to tell "find" not to process sub-directories.

    These are the 3 different command formats I've tried:

    /tmp/ > find /tmp -name "bar_*.txt" -type f -prune -mtime +1
    find: cannot read dir /tmp/smc898: Permission denied
    find: cannot read dir /tmp/https-fpdbtst1.fuelman.com-ab0d7966: Permission denied
    find: cannot read dir /tmp/hsperfdata_oracle: Permission denied
    /tmp/bar_1.txt

    /tmp/ > find /tmp -name "bar_*.txt" -mtime +1 -type f -prune
    find: cannot read dir /tmp/smc898: Permission denied
    find: cannot read dir /tmp/https-fpdbtst1.fuelman.com-ab0d7966: Permission denied
    find: cannot read dir /tmp/hsperfdata_oracle: Permission denied
    /tmp/bar_1.txt

    /tmp/ > find /tmp -name bar_*.txt -mtime +1 -type f -prune
    find: cannot read dir /tmp/smc898: Permission denied
    find: cannot read dir /tmp/https-fpdbtst1.fuelman.com-ab0d7966: Permission denied
    find: cannot read dir /tmp/hsperfdata_oracle: Permission denied
    /tmp/bar_1.txt

    tia

  2. #2
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Try
    Code:
    find /tmp -depth -name "bar_*.txt" -mtime +1 -type f -prune
    Regards

  3. #3
    Join Date
    Feb 2006
    Posts
    173
    Provided Answers: 1
    fpdbtst1:/tmp/ > find /tmp -depth -name "bar_*.txt" -mtime +1 -type f -prune
    find: cannot read dir /tmp/smc898: Permission denied
    find: cannot read dir /tmp/https-fpdbtst1.fuelman.com-ab0d7966: Permission denied
    find: cannot read dir /tmp/hsperfdata_oracle: Permission denied
    /tmp/bar_1.txt


    ...Same results

  4. #4
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Hi,

    Don't exactly know why but I think this:
    Code:
    find /tmp ! -name . -prune -name "bar_*.txt" -mtime +1 -type f
    will work. Adopted from the stuff written here http://www.in-ulm.de/~mascheck/various/find/

    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •