1

I am trying to obtain a list of files using the find command as follows:

find . \( -iname @eaDir -o -iname .DS_Store -o -iname Thumbs.db \) -prune -o -mtime -25 -type f -printf "%P\n"

This is working fine.

However, if I try to redirect the output of the above command to a file, the latter remains empty:

FILES_TO_BACKUP=/tmp/__$$_myfiles.lst
find . \( -iname @eaDir -o -iname .DS_Store -o -iname Thumbs.db \) -prune -o -mtime -25 -type f -printf "%P\n" > $FILES_TO_BACKUP

Anyone has any idea why?

  • Which flavor of find is this? find on Mac OS X 10.11 lacks a -printf flag. – thrig Feb 27 '17 at 17:20
  • any chance you changed directories in-between? – Jeff Schaller Feb 27 '17 at 17:34
  • Try adding the -print switch to find rather than -printf? – DopeGhoti Feb 27 '17 at 17:40
  • @thrig: I'm on CentOS 7.3 Core – EEM RT Feb 28 '17 at 10:46
0

Are you changing user or similar between invoking from the script and running from command line? If so, perhaps the PATH has changed and a different find is being executed.

With peculiar problems like this I often run the command with 'strace' to see what it is doing differently.

From the two invocations that you gave I cannot eyeball any difference, there is perhaps a hint that you're running the second from a script, so perhaps that's where the difference is. Could you run 'pwd' before both, just to ensure that they are running from the same location and a 'which find' too may be helpful.

  • I'm not changing user, but yes, the 2nd one is being run from within a script. Am not familiar with strace. Tried displaying the output of pwd and I confirm that the path is correct. which find: /usr/bin/find – EEM RT Feb 28 '17 at 10:51
  • OK. After leaving the script run until the end, I did get the output in the file. – EEM RT Mar 2 '17 at 16:03

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.