0

In my Java application , I am running following command to get the Octal permission and file name.

stat -c "%a %n" <file name>

This command works on Linux but the Solaris version I have doesnt have stat command supported.

How can I achieve this with a command which works on both Linux and Solaris There are some options with perl stat but unfortunately I cant use perl.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Bankelaal
  • 408
  • 1
  • 9
  • 24
  • Also see [How to manage linux file permissions in Java](https://stackoverflow.com/q/15568629/608639). Asking for a `stat` command replacement on Solaris is mostly off-topic for Stack Overflow. You might want to ask for a Posix command replacement at [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/). – jww Nov 14 '17 at 14:11

1 Answers1

0

You can achieve same thing using find command

find <file name> -printf "%m %f"

find <directory name> -maxdepth 0 -printf "%m %f"

Example:

find /etc/passwd -printf "%m %f"

find /etc -maxdepth 0 -printf "%m %f"
Deepak Dixit
  • 1,510
  • 15
  • 24