2

My setup is as following:

folder structure

dir
 |--correctfile1
 |--correctfile2
 |--correctfile3
 |--subdir1
   |--wrongfile1
   |--wrongfile2
   |--wrongfile3
 |--subdir2
 |--subdir3

I need to find out if there are files in dir that are older than 3 minutes. This means I should ignore folders subdir1, subdir2 and subdir3 and only search in the main directory dir

I have following one-liner

find $dir -mmin +3 -type f

but this prints also the files from subdir1

Some extra info:

AIX 5.3

find command does not have -maxdepth, -mindepth, -or, -not or -path options


The manpage: http://textuploader.com/oe0r

3
  • 1
    +1 for "find command does not have -maxdepth, -not or -path options" info... Commented Dec 11, 2014 at 14:47
  • Why find does not have that options? can you upload the man page of that and post the link? may be it use another option for that. Commented Dec 11, 2014 at 14:48
  • @KasiyA: I added the manpage
    – Noosrep
    Commented Dec 11, 2014 at 14:53

1 Answer 1

1

A portable way to prevent find from recursing is to execute the -prune action on directories other than the toplevel directory.

find "$dir" \! -name "$(basename -- "$dir")" -type d -prune -o -mmin +3 -type f -print
12
  • No filenames, just the name of $dir so in the above example: dir
    – Noosrep
    Commented Dec 11, 2014 at 15:17
  • @TimothyPersoon And if you add -print after -type f? Commented Dec 11, 2014 at 15:22
  • then it returns nothing
    – Noosrep
    Commented Dec 11, 2014 at 15:23
  • @TimothyPersoon Are there files in dir which match -mmin +3? Does your find $dir -mmin +3 -type f return files which are not in a subdirectory? Commented Dec 11, 2014 at 15:25
  • 1
    I'd use find $dir \( ! -name $(basename $dir) -type d -prune \) -o -mmin +3 -type f -print
    – wurtel
    Commented Dec 11, 2014 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .