Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Argument-less file calls can be quite slow, e.g. for videos it will tell you everything about the encoding. Commented Nov 6, 2016 at 17:27
  • Also you are assuming no file starts with -. Commented Nov 6, 2016 at 17:29
  • And I see no reason why you wouldn't just do a single call to file, it can take multiple files as arguments. Commented Nov 6, 2016 at 17:45
  • @phk, to address your comments: (1) it's good to know the potential slowness, but I see no POSIX way to prevent that; (2) I make zero assumptions about file names, as the find command will prefix ./ to any filename passed to the shell command; (3) Using grep as a test on a single file command output at a time is the only POSIX way I can see to guarantee correct handling of filenames that may contain newlines. Commented Nov 6, 2016 at 18:59
  • I looked over your final "POSIX-y" solution and I think it's clever—but you assume that file supports the --mime-encoding flag and the -- separator, neither of which is guaranteed by POSIX. Commented Nov 6, 2016 at 19:02