- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Display the file permission (rw-r--r--) in to ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 09:04 PM
03-08-2010 09:04 PM
I need help on capture the listing of lots of files in multiple file systems and directories and instead of listing this file permission as (rw-r--r--) this I need to display in traditional permission format?
Is there any way to do this in HP-UX?
I have been running some thing like this to get the information.
find /m4 -type f -exec ll -d {} \; > file.perm.lst
Appreciate your help in advance.
Regards,
MP
Solved! Go to Solution.
- Tags:
- Permission
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2010 09:10 PM
03-08-2010 09:10 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
One more correction to my note.
I need the permission listing in "number" format.
r--r--r-- = 444
Sorry if I confuse the crap out of you guys.
Regards,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 01:07 AM
03-09-2010 01:07 AM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
Why would you want this obsolete format?
I have a tool that converts to the symbolic format:
chmod u=r,g=r,o=r
See my scripts in this thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1215123
It shouldn't be that hard to convert to octal numbers if you insist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 05:11 AM
03-09-2010 05:11 AM
SolutionUse Perl and you could do:
# cat ./showperms
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my $path = shift || qq(.);
find(
sub {
if ( -f $_ ) {
my $mode = ( stat(_) )[2];
printf "%04o %-s\n", $mode & 0777, $File::Find::name;
}
},
$path
);
1;
...run as:
# ./showperms /path
...or to analyze the current directory run without arguments:
# ./showperms
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 05:14 AM
03-09-2010 05:14 AM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 12:16 PM
03-09-2010 12:16 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
The reason I need the number format because after the upgrade of the app if things needs to go back the way it was then I wanted run quick loop to restore the permission of the file because we are change the permission on the files prior to upgrades.
Regards,
MP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 12:57 PM
03-09-2010 12:57 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
> The reason I need the number format because after the upgrade of the app if things needs to go back the way it was then I wanted run quick loop to restore the permission of the file because we are change the permission on the files prior to upgrades.
That was pretty clear. So what's wrong with the Perl script I offered? It produces output like:
# ./showperms /etc | head
0644 /etc/fstab
0444 /etc/group
0444 /etc/passwd
0444 /etc/magic
0444 /etc/nfssec.conf
0644 /etc/hosts
0444 /etc/services
0444 /etc/inetsvcs.conf
0664 /etc/.prev.ioconfig
0600 /etc/lvmtab
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 01:29 PM
03-09-2010 01:29 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
Thanks a lot, I was not questioning anyone but just trying to reply Dennis's question.
Thanks for your help that is what I was trying to accomplish.
Appreciate your help. Now I have to figure out the loop just in case if I have to revert back things.
Regards,
MP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 01:39 PM
03-09-2010 01:39 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
Assuming you use JRF's PERL snippet and send the output to a file, this should come close to working:
while read PERM FILE
do
echo "Changing permission on ${FILE} to ${PERM}"
chmod ${PERM} ${FILE}
done < perm-list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 03:21 PM
03-09-2010 03:21 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
Is it possible to make your code read under the link fron the root level?
Patrick, great code, thanks for the information. Love the way it gives the format. But not reading under the directory level. I can stick with JR's script.
Thanks,
MP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 04:57 PM
03-09-2010 04:57 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
> Is it possible to make your code read under the link from the root level?
You can pass any argument to the script that represents a directory or filesystem. If you want to start at the root filesystem, do:
# ./showperms /
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 05:32 PM
03-09-2010 05:32 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
A small change to the script allows us to pass one or more arguments. Once again, passing nothing infers search the current working directory. Use:
# cat ./showperms
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my @dir = @ARGV ? @ARGV : ('.');
find(
sub {
if ( -f $_ ) {
my $mode = ( stat(_) )[2];
printf "%04o %-s\n", $mode & 0777, $File::Find::name;
}
},
@dir
);
1;
...to do things like:
# ./showperms /etc /sbin /usr/local/bin
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2010 09:15 PM
03-09-2010 09:15 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
That was the purpose of those scripts on that thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2010 07:52 PM
03-11-2010 07:52 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
Thanks for your help, I got what I wanted but just a quick question.
On the script that Patrick attached, can it be possible to make it read underneath the directory level and all the files under that directory?
Once again, thanks for all your help.
See attached.
Regards,
MP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2010 08:45 PM
03-11-2010 08:45 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
For example:
# ./showperms /etc
0644 /etc/fstab
0444 /etc/group
0444 /etc/passwd
0444 /etc/magic
0444 /etc/nfssec.conf
0644 /etc/hosts
0444 /etc/services
0444 /etc/inetsvcs.conf
0664 /etc/.prev.ioconfig
0600 /etc/lvmtab
(From one of JRFs posts above)
To make that script send its ouput to a file, you would run it like:
# showperms /etc > perm_file
The you would use perm_file as the input for my script.
Run JRF's script on whatever directory you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2010 10:05 PM
03-11-2010 10:05 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
Sorry I was not clear in my note. I was talking about the getmod.sh (attachment) that you put in your post.
I apologize for my confusions.
Regards,
MP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2010 05:58 AM
03-12-2010 05:58 AM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
You could do a 'getchmod.sh /*' and it looks like it should work from the / directory onwards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2010 06:04 AM
03-12-2010 06:04 AM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2010 07:40 AM
03-12-2010 07:40 AM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
for DIR in $(find / -type d -print)
do
getchmod.sh ${DIR}/* ${DIR}/.*
done
This will find ALL directories on the system, starting at /, and run getchmod.sh on them, including any hidden directories.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2010 09:54 AM
03-12-2010 09:54 AM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
>>>>>> Regarding the 'getchmod.sh' script -- If you run the script as 'getchmod.sh /*' are you wanting it to be recursive and just go through ALL directories and files on your system? >>>>>
You right that was Pete, it was too late when I was replying this last night. :-(
JRF's script was awesome, the only reason I was messing around with "getmod" because it was giving me output in one file but it was not doing *Recursive* even if I was doing 'getchmod.sh /*'.
Currently, I have to two different commands to get the ownership (using find connand) and permission in (number format using JRFâ s).
find /m4/* -type f -exec ll {} \; | awk '{printf $1" "$3":"$4" "$9"\n"}' > perm-list.
-r--r--r-- c346538:edi /m4/app16/test1.db
This gives me the format and then I run your little loop to restore things back (C.M.B).
I will try your last loop and let you know.
I think I have all the pieces in place to do what I need.
Thanks again to JRF, Patrick, Dennis and Pete and all the guys that reply to my note.
Thanks,
MP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2010 04:38 PM
03-12-2010 04:38 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
The last loop Patrick suggested has worked, thanks for your help.
Once again, thanks to JRF, Patrick, Pete and Dennis.
Regards,
MP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2010 02:08 PM
03-15-2010 02:08 PM
Re: Display the file permission (rw-r--r--) in to numbers on lots of file
ls -l | awk '{print $1" " $9}' | while read PERM FNAME
do
DPERM=$(echo $PERM | tr rwx 421 | sed -e 's/./ &/g' | awk '{s1=$2+$3+$4; s2=$5+$6+$7; s3=$8+$9+$10; print s1 s2 s3}'
echo "DPERM $FNAME"
done