mkdir: copying a folder's permissions

Hi,

I wanted to know how to create a folder using mkdir and then have it copy the permissions from another specified folder on the system.

For example if I did this:

mkdir /Volumes/USBSTICK/System

How can I make it copy the permissions from the /System folder ?

Thanks

Solaris 10:
To copy permissions (and ACLs):

getfacl /directory > filename

To apply permissions

setfacl -f filename /new/directory

<edit>
This doesn't change the owner of the directory

To identify ownership and permissions of a directory:

ls -l /path/that/source/directory/is/in | grep directory
Then change the ownership of the new directory:
chown owner:group /target/directory

The permissions will appear as -rw-rw-rw or -rwx------ or something of that ilk

The first 'digit' will usually be -, but may be 4, 2 or 1 (depending on what has been configured - run a man on chmod for more details)
The next 3 sets of digits are the permissions for owner, group, and others (respectively).

To change the permissions of a directory, you will need to identify who needs
Understanding (r)ead (w)rite or e(x)ecute involves some math:
For:

Read = 4   Write = 2   Execute = 1
--x = 1
-w- = 2
-wx = 3
r-- = 4
r-x = 5
rw- = 6
rwx = 7

So, to set Read & Write for the OWNER only, you would:

chmod 600 filename

# ls -l filename
-rwx------   1 root     root           0 Aug 19 14:47 filename

</edit>

Good ol' cp uses a -p or --preserve, and if its a directory just slap a -r onto it like so

cp -p -r DIR1 DIR1_NEW

chompy - I would recommend cp -rp if the directory was empty, but this copies the entire directory tree...

@avronius,

I could probably use that method and then make a shell script out of it. However, I was wondering if there was an easier way to get the permissions in plain number format rather than using ls and doing the conversion.

@chompy

That works, but unfortunately I don't want to copy the entire directory, just its permissions.

Thanks