Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to search through about 7,000 directories and determine the number of PDFs modified last month grouped by the type of PDF, which is in a MySQL database. The folder structure is...


Currently I'm running...

find "/folder/to/FORMID/" "/folder/to/FORMID/" "/folder/to/FORMID/"  -name '*.pdf' -mtime +31 -mtime -51 | wc -l

except with up to 4,000 directories as parameters. This isn't returning what I know to be accurate results.

Is this the most efficient way to do this or is there another linux command I can use?

share|improve this question

closed as off topic by Michael Hampton, Frands Hansen, Webnet, Ward, Scott Pack Sep 26 '12 at 13:39

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

You say you want to do this within the last 30 days, why is your find +31 and then -51? That is GREATER than 31 days and LESS than 51 days. – mdpc Sep 20 '12 at 19:29
@mdpc - Updated, not the last 30 days, the last month – Webnet Sep 20 '12 at 19:54
Is there some reason why you don't just start your find at the top level directory? find /folder/ -name '*.pdf' ...? I don't understand why you think you need to list each directory individually? You can use additional operators if you want to set a min/max depth, or match a portion of the path. – Zoredache Sep 20 '12 at 20:04

If you have a file which containts the names of the directories to search, you could do this shell/find combination:

for i in `cat LIST_OF_DIR_NAMES.TXT`; do find ${i} -mtime +31 -mtime -51 -name '*.pdf' ; done | wc -l

This will run find on each directory in LIST_OF_DIR_NAMES.TXT and give you the total files found.

share|improve this answer

Find should work appropriately. Since the command is running, I'm assuming it's not a too many / too long arguments error. Give that, it may be a bug in find. There are many options that can reasonably work around that. Here are two:

  • Scripting instead of using find directly
  • Using args -n $NUM to check $NUM directories per run of find

    cat directory_list | xargs -n 30 -IX find X -mtime +31 -mtime -51 -name '*.pdf'

I'm assuming that you have many subdirectories that you intend to not read, hence not specifying a single higher-level directory.

share|improve this answer

If you want PDFs modified WITHIN the last 30 days, wouldn't you do something like this:

 find dir1 dir2 ... dirn -name '*.pdf' -mtime -31 -print
share|improve this answer
The problem is not the time frame, I have that part successful. The problem is that when I add this many paths is screws up. – Webnet Sep 20 '12 at 19:32
If you have 'spaces' or special characters in the filename when the wc command might have problems. – mdpc Sep 20 '12 at 19:34
Also, remember time increases as you run the commands, thus if files are on the cusp of a number of days increase it could vary depending on how long things take to do a find. – mdpc Sep 20 '12 at 19:37

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