0

Can anyone provide Solaris equal command to the following command

$ find . -type f -printf '%f,%h\n'

After running the code I am getting "bad option printf find: [-H | -L] path-list predicate list error "

Printf is not supported by Solaris UNIX environment

Please refer to following links for more information:

https://askubuntu.com/questions/818478/how-to-create-a-new-file-which-provides-filename-and-its-source-directory-inform/818480

http://explainshell.com/explain?cmd=find+sample+-type+f+-printf+%27%25f%2C%25h%5Cn%27

Thanks in advance

1

The -printf action is specific to GNU find, so it isn't available on platforms that don't run GNU find. Only non-embedded Linux and Cygwin run GNU find unless you've installed it separately.

You can install GNU find on Solaris.

Alternatively, you can rewrite your script to use only portable features. There is no generic way to translate -printf: different specifiers will need different tools. For %f and %h, it's easy, since these are just parts of the file name. If the file name is in a shell variable x, you can use parameter expansion constructs to extract the base name (remove the prefix */) and the directory name (remove the suffix /*).

find . -type f -exec sh -c 'for x do printf %s,%s\\n "${x##*/}" "${x%/*}"; done' sh {} +
  • Hi Thanks for the solution. But i am getting ; unexpected error while running the code – vinod kumar Aug 31 '16 at 6:06
  • @vinodkumar Oh right, remove the ; before do, that's a common but non-standard syntax. – Gilles Aug 31 '16 at 7:46
  • Now getting find:incomplete statement error – vinod kumar Sep 1 '16 at 23:39
  • @vinodkumar Did you copy the command exactly? Are you using some extremely ancient version of Solaris that doesn't support -exec … {} +? Are you calling /usr/bin/find or /usr/xpg4/bin/find? – Gilles Sep 2 '16 at 7:07

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.