|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
|||
|
|||
|
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}'
|
|
#5
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > How to check chmod of a file/directory? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|