UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old November 19th, 2004, 11:43 AM
yongho yongho is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 57 yongho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 38 m 20 sec
Reputation Power: 5
How to check chmod of a file/directory?

How can I retrieve the chmod number values (like 755.. 777..) for a given directory or file instead of viewing it as rwx--rwx etc..

There is a directory with these values..
drwxrwSr-x
and I am trying to duplicate it...
and I can't, because I don't know how.
Especially for that big S in there.

Reply With Quote
  #2  
Old November 19th, 2004, 03:46 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
perl python and C all implement a stat function. But you have to know how the C macros work first.

One of values stat returns is called the mode. in C:
Code:
typedef 
{
       dev_t    st_dev;       /* ID of device containing a */
                                  /* directory entry for this file */
           ino_t    st_ino;       /* Inode number */
           ushort   st_fstype;    /* Type of filesystem this file  */
                                  /* is in; see sysfs(2) */
           ushort   st_mode;      /* File type, attributes, and */
                                  /* access control summary */
           ushort   st_basemode   /* Permission bits (see chmod(1)) */
           ushort   st_nlink;     /* Number of links */
           uid_t    st_uid;       /* User ID of file owner */
           gid_t    st_gid;       /* Group ID of file group */
           dev_t    st_rdev;      /* Device ID; this entry defined */
                                  /* only for char or blk spec files */
           off_t    st_size;      /* File size (bytes) */
           time_t   st_atime;     /* Time of last access */
           time_t   st_mtime;     /* Last modification time */
           time_t   st_ctime;     /* Last file status change time */
                                  /* Measured in secs since */
                                  /* 00:00:00 GMT, Jan 1, 1970 */
           long     st_blksize;   /* File system block size */
           uint     st_acl:1;     /* Set if the file has optional */
                                  /* access control list entries */
                                  /* HFS File Systems only */
} stat;


This is from HPUX, but st_mode has all of the permissions bits plus the special bits set.
There are a series of macros defines in <sys/stat.h> that let you determine which bits are set.

The discussion/code for this is pretty involved. You want to google for
'st_mode file permission' and see if you can find an example.

Reply With Quote
  #3  
Old November 19th, 2004, 03:52 PM
Boki's Avatar
Boki Boki is offline
A wanna-be guru of some sort
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Location: Either online or offline
Posts: 624 Boki User rank is Sergeant (500 - 2000 Reputation Level)Boki User rank is Sergeant (500 - 2000 Reputation Level)Boki User rank is Sergeant (500 - 2000 Reputation Level)Boki User rank is Sergeant (500 - 2000 Reputation Level)Boki User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 4 h 7 m 13 sec
Reputation Power: 13
s is for set group id, meaning that all the files in that directory will have the same permissions, if I remember correctly. So in your case the octal representation is 775, I think... not 100 % sure.

Reply With Quote
  #4  
Old November 19th, 2004, 06:12 PM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
A couple of years ago, several of us collaborated on this problem (here).

The final solution....
Code:
#!/bin/ksh
ls -ld $* | awk 'BEGIN {
v["r1"]=400; v["w2"]=200; v["x3"]=100; v["s3"]=4100; v["S3"]=4000
v["r4"]=40 ; v["w5"]=20 ; v["x6"]=10 ; v["s6"]=2010; v["S6"]=2000
v["r7"]=4  ; v["w8"]=2  ; v["x9"]=1  ; v["t9"]=1001; v["T9"]=1000}
{val=0
 for (i=1;i<=9;i++) val=val+v[substr($0,i+1,1)i]
 printf "%4d %s\n",val,$NF}'

Reply With Quote
  #5  
Old December 7th, 2004, 02:54 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
try:

mkdir target_directory
cd source_directory
find . | cpio -pmduv target_directory

You will get an exact copy of source directory inclusive permissions. Simple cp would change permissions.

Big S means: appropriate s bit is set, but the appropriate x bit is not set.

to set suid bit write chmod 4000, for guid bit chmod 2000. In your case
drwxrwSr-x means 2765, so write

chmod 2765 target .

Simple and effective.

Longer way would be

chmod 765 target
chmod g+s target .

Regards

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > How to check chmod of a file/directory?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway