# How to keep directory permissions with cpio ?



## olivier (Aug 26, 2009)

Hi,

Under my NanoBSD system, I need to copy all files and directories (that are differents from a reference).
And because the destinations directories don't exist, I'm using cpio.

Here is an extract of my shell script:


```
(
    cd /etc
    for i in "$@" `find * -type f`
    do
        if [ -f /cfg/$i ]
        then
            cmp -s /etc/$i /cfg/$i || cp -pfv /etc/$i /cfg/$i 2>/dev/null
        else
            cmp -s /conf/base/etc/$i /etc/$i || (find $i -print | cpio -dumpv /cfg/ 2>/dev/null)
        fi
    done
)
```

This script compare the file between /cfg and /etc, or /conf/base/etc and /etc and copy all modified file to /cfg.

The problem is that cpio don't preserve directory permission:

```
[root@router]~#ls -alh /conf/base/etc | grep local
drwxr-xr-x   6 root  wheel      512B Aug 25 21:08 local
[root@router]~#ls -alh /cfg | grep local
drwx------   3 root  wheel   512B Aug 26 15:39 local
```
And I didn't find what cpio parameter to use for keeping permission.
I've tried to add "-depth" option to find (as reported here), but no changes.

Anyone have an idea ?

Thanks


----------



## vivek (Aug 26, 2009)

Look at -o and -i option. 



> Permissions of the files will be the same as the permissions associated with the files copied out using cpio	-o.


----------



## olivier (Aug 26, 2009)

I've the problem by replacing this line:

```
for i in "$@" `find * -type f`
```
by:

```
for i in "$@" `find * -depth`
```


----------

