Visit Our UNIX and Linux User Community


mkdir: copying a folder's permissions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mkdir: copying a folder's permissions
# 1  
Old 08-19-2009
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
# 2  
Old 08-19-2009
Solaris 10:
To copy permissions (and ACLs):
Code:
getfacl /directory > filename

To apply permissions
Code:
setfacl -f filename /new/directory


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

To identify ownership and permissions of a directory:
[code]ls -l /path/that/source/directory/is/in | grep directory[code]
Then change the ownership of the new directory:
Code:
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:
Code:
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:
Code:
chmod 600 filename

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

</edit>

Last edited by avronius; 08-19-2009 at 06:00 PM..
# 3  
Old 08-19-2009
Good ol' cp uses a -p or --preserve, and if its a directory just slap a -r onto it like so
Code:
cp -p -r DIR1 DIR1_NEW

# 4  
Old 08-19-2009
chompy - I would recommend cp -rp if the directory was empty, but this copies the entire directory tree...
# 5  
Old 08-19-2009
@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

Previous Thread | Next Thread
Test Your Knowledge in Computers #142
Difficulty: Easy
Version 4 Unix was rewritten in C in 1977.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script for mkdir with permissions

Hello, I'm pretty new to scripting and trying to do a simple (well, I thought so) administrator task. I'm using bash. I want to create 10 directories under the one directory and apply permissions at the same time. I've worked out the make directories part: mkdir /userdata/folder{1..50}... (7 Replies)
Discussion started by: jimothy007
7 Replies

2. Ubuntu

Folder permissions

Hi Team, I want to set permissions to one folder in such a way that the user can write files or create folder inside that but should not able to delete it. Basically reason behind this is i am using Pidgin Messenger. There is a directory of logs in which, when user chat its store his logs.... (2 Replies)
Discussion started by: paragnehete
2 Replies

3. Red Hat

Need to compare two folder / FS permissions

Hi, Need to compare two folders / File systems permissions & time stamps including sub folders and files. Kindly let me know if any commands available. Regards :: VM (1 Reply)
Discussion started by: novaothers
1 Replies

4. Shell Programming and Scripting

Folder permissions to delete

I am using the below command to delete files from directories and subdirectories find /test/abc/xyx -type f -mtime +7 -exec rm -f {} \; there are some subfolders in xyx for which i don't have permission to delete. Is there a way i can check the permission of the folder first and then delete... (4 Replies)
Discussion started by: ch33ry
4 Replies

5. Homework & Coursework Questions

Copying Folder, C program

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Copying all the normal files from 1 folder to another on a unix platform. I pass in 1 or 2 arguments, the folder... (0 Replies)
Discussion started by: MW99
0 Replies

6. UNIX for Dummies Questions & Answers

Permissions issue after copying files

Hi everyone, I am using mac os x 10.6, and I just copied over a project from a machine with 10.5... And I noticed my ls color is very funky in this directory... I found that my permissions are all messed up, and am wondering if there is a way to recursively fix permissions? This is how they... (3 Replies)
Discussion started by: patrick99e99
3 Replies

7. Shell Programming and Scripting

Copying latest file into a folder

Hello all, this is my first post while i am trying to understand unix. I would basically like to know if i can do this: Lets say i have a folderA and folderB And i save something in folderA Can i make a script that checks folderA latest file, then compares it with the date of latest file in... (16 Replies)
Discussion started by: takissd
16 Replies

8. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

9. Windows & DOS: Issues & Discussions

folder permissions

I work for a big company and all the people within my unit share a common drive to save documents to. I am listed in the group(AMS group) that has access rights to folders within this drive. but i'm trying to restrict access to a confidential folder so that only I can access it. when I set the... (0 Replies)
Discussion started by: shed
0 Replies

Featured Tech Videos