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 Answers1

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 {} +