2

I have had a few tasks where I needed to make reports on file changes on directories from different servers and have managed to make the reports using simple Unix commands. I used:

ls -R -lT /Volumes/www/subdir/ | awk '{if ($7=="" ) print $0; else print $11";"$7"/"$8"/"$10;}' > /Users/[username]/Desktop/output.txt 

Now I need to make a report of all the PDF files that are missing metadata. I was wondering if there is a way (much like my current method) to check the metadata of a file and output only the ones with missing metadata. I want to pipe the ls results to a file so that i can import the data to exel. In my other reports I used awk to format the ls output so that it could be imported into exel.

This operation will be done on a Mac and prefer to use built-in commands over installing, as I do not have admin rights to install software on office hardware.

Update: This report will be modified to not only report on PDFs but I foresee having to report on other file types in the future. So a report may search one or many file types.

The meta data I need to check for right now is:

  • title
  • author
  • subject
  • keywords

I have managed to list out a files metadata using:

mdls [path to file]

This results in a list of all the meta data. I tested it with a pdf with meta filled out and one without the meta filled out. I noticed with the missing meta data it is not returning null but rather not listing the mata key at all.

Something i'm currently trying is:

mdfind -onlyin /Volumes/web/ "kMDItemAuthors == ''"

How could I use this data to filter the output of ls

Update: I managed to get a report that lists all pdfs, by using the following:

ls -R -lT [server directory path] | grep ".[file extension]" | awk '{print $11";"$7"/"$8"/"$10;}' > [output file path] 

One of the side effects of this is that i'm losing the recursive property from the ls. Still working on this.

I also need to find a way to filter only the ones that are missing the required metadata. I have also been advised I need to also make a report of the PDFs that have all the metadata as well. I have tried using this current command and piping the output to mdfind first then to awk but I must be missing something.

  • Can you specify "missing metadata" some more? If you want to check if a PDF has no metadata at all (which I'm not sure is allowed by the spec) you could grep binary for the PDF/XMP tags. For a higher level check, try with pdfinfo which is part of xpdf which might or might not be bundled in Mac OSX, not sure. – kba Feb 17 '16 at 17:47
2

Use exiftool.

To print full path (-T -FilePath) to all files with extension pdf recursively (-r) in /search/path that have either of your specified metadata empty, use:

exiftool -T -FilePath \
         -if '$FileTypeExtension eq "pdf"' \
         -if '(not $Title) or (not $Author) or (not $Subject) or (not $Keywords)' \
         -r /search/path

Customize the command to suit your future needs.

  • Is this included with the default OS X? we are not permitted to install anything if its not included. – Patrick W. McMahon Feb 17 '16 at 22:22
  • This is a perl script, no "installation" required. – techraf Feb 17 '16 at 22:27
  • I will test this in the morning when i have access to the mac again. at this time of day I don't have access to it. – Patrick W. McMahon Feb 17 '16 at 22:36
  • The error i get is exiftool: command not found – Patrick W. McMahon Feb 18 '16 at 21:07
  • The office mac doesn't have exiftool – Patrick W. McMahon Feb 19 '16 at 14:13
0

If you want something more generic, you'd have to create some program/script to do the checking for one file, and use find(1) to run it on each target in turn, something like:

find . -name "*.pdf" -exec check \;

where you make sure that check file always returns success (0), and prints the name of the offending file as appropriate. Or tweak the above to just return success if the file is broken, and go:

find . -name "*.pdf" -exec check \; -print

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.