Aimed systems: Linux and OS X. Original code which works in Ubuntu 16.04 but not OS X, but follows unsuccessfully POSIX standards

gfind ~ ! -readable -prune -o -type f -name "*.tex" 


  • ! is about Negation of a primary; the unary NOT operator.
  • -readable TODO this does not seem to be POSIX
  • -prune is about The primary shall always evaluate as true; it shall cause find not to descend the current pathname if it is a directory. If the -depth primary is specified, the -prune primary shall have no effect.
  • -o is about Alternation of primaries; the OR operator. The second expression shall not be evaluated if the first expression is true. That is if not, then this.
  • -type about type, here file f
  • -name about filename, here *.tex


gfind: paths must precede expression: type
Usage: gfind [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

Fix proposal

Use -perm 0744 instead of -readable but not sure if it is equivalent

gfind ~ ! -perm 0744 -prune -o -type f -name "*.tex" 

Output: /Users/masi. Expected output: list of .tex files.

How can you set permissions of find correctly for readable?

  • 4
    Well where did you get find from and what version as it is not part of OSX (in general from your other posts Linux is not Unix they differ if you want non standard things stick to Linux :) If you want the same in general don't use GNU extensions – mmmmmm Jun 2 '16 at 11:37
  • 4
    As I said don't use GNU extensions - some things will differ but BSD is normally a subset - i.e. don't assume that Linux is the correct way, – mmmmmm Jun 2 '16 at 11:46
  • 1
    If you truly want to write portable scripts then I suggest you start here- pubs.opengroup.org/onlinepubs/009695399/utilities/contents.html to learn the POSIX standards for the shell and its utilities. Most scripts that I write in OS X will run in Linux. – fd0 Jun 2 '16 at 18:29
  • I'm going to let you do the work. Add the -user option (It can be a variable) then check whether the -perm is readable. – fd0 Jun 2 '16 at 19:13
  • 1
    In patrix find . -perm +0666 example, it is possible to list a file where the owner is not the caller but only that owner can read the file. -perm reads permission bit without regards to the file's classifications. So, building find 's logic may involve using the -user and -groupoptions along with -perm options. Of course this can be overly complex and hard to debug. I'll post a solution when I have time to test it. – fd0 Jun 3 '16 at 13:23

The double negation at the beginning makes this rather complex. Just using

gfind . -readable -type f -name '*.tex'

should work.

PS: Or find . -perm +0666 -type f -name '*.tex' for the default find.

| improve this answer | |
  • Thank you for pointing out the double negation! I have had it all the time in mind but could not find a way to solve it. – Léo Léopold Hertz 준영 Jun 2 '16 at 19:54
  • Do you know what fd0 means about -user option here in his comment? I am still thinking about it but I cannot understand. – Léo Léopold Hertz 준영 Jun 2 '16 at 20:05
  • 1
    Don't see how -user (which checks for ownership, not readability) would help here. But maybe @fd0 can throw some light on it. – nohillside Jun 3 '16 at 4:10

After attempting to use find's options -user,-group, and -perm, the find command quickly became unmanageable. An inline script with find using the shell's -r test would be portable between the two operating systems.

find ~ -type f -name '*.tex' -exec sh -c 'for file
    [ -r "$file" ] && echo "$file"
' sh {} + 2>/dev/null
| improve this answer | |

You must log in to answer this question.

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