1822933 Members
3823 Online
109645 Solutions
New Discussion юеВ

printf

 
Sanjiv Sharma_1
Honored Contributor

printf

This command works for linux.
abcd@xyz:~> find /tmp -printf %m -maxdepth 0 | grep 1777
1777

How can I achieve this in HP-UX 11.11? Thanks in advance.
Everything is possible
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor

Re: printf

You will have to install the Gnu version of find or choose to code your script in a more portable manner.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: printf

Here is what you need although I am not fond of non-portable solutions.

http://hpux.its.tudelft.nl/hppd/hpux/Gnu/findutils-4.2.28/
If it ain't broke, I can fix that.
Sanjiv Sharma_1
Honored Contributor

Re: printf

Thanks. Is there any command/syntax through which I can get the permission of a file or directory in the number format?
like 1777 etc..
Everything is possible
Dennis Handly
Acclaimed Contributor

Re: printf

Neither -printf nor -maxdepth work on HP-UX. You first will have to explain what they do?

There is -depth option.

I assume -printf %m prints the mode? To do that, you need:
$ find /tmp -exec ll + | grep "^lrwxrwxrwx"
James R. Ferguson
Acclaimed Contributor

Re: printf

Hi Sanjiv:

> Is there any command/syntax through which I can get the permission of a file or directory in the number format?

# perl -le '$f=shift;printf("%04o %-s\n",(stat($f))[2] & 07777,$f)' file

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: printf

Hi (again) Sanjiv:

Since you began this query with the piped output of 'find', here's another Perl variation that you can use in a pipeline:

# find /path -type f -print|perl -nle '{printf("%04o %-s\n",(stat($_))[2] & 07777,$_)}'

...OR (better yet) do everything in Perl:

# perl -MFile::Find -le 'find(sub{printf("%04o %-s\n",(stat($_))[2] & 07777,$File::Find::name)},@ARGV)' /path

Regards!

...JRF...

Sanjiv Sharma_1
Honored Contributor

Re: printf

Ok. I am using the following command for now:
ls -ld /tmp | grep "^drwxrwxrwt"
Everything is possible