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

  • 1
    +1 for "find command does not have -maxdepth, -not or -path options" info... – Hauke Laging Dec 11 '14 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. – αғsнιη Dec 11 '14 at 14:48
  • @KasiyA: I added the manpage – Noosrep Dec 11 '14 at 14:53
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
  • No filenames, just the name of $dir so in the above example: dir – Noosrep Dec 11 '14 at 15:17
  • @TimothyPersoon And if you add -print after -type f? – Hauke Laging Dec 11 '14 at 15:22
  • then it returns nothing – Noosrep Dec 11 '14 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? – Hauke Laging Dec 11 '14 at 15:25
  • 1
    I'd use find $dir \( ! -name $(basename $dir) -type d -prune \) -o -mmin +3 -type f -print – wurtel Dec 11 '14 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.