Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm in the middle of Samba update on a number of servers, each with several shared directories. Users are authenticated against Windows domain AD, so I expect change in local UIDs on Linux boxes. I'd like to know if there is a way to dump ownership of all shared directories so I don't have to set it manually, but to restore it after upgrade.

share|improve this question
up vote 1 down vote accepted

you could do it by using a script.

1) Dump the directories (the names) in a file. 2) Use find path -type d (This is to print every directory under the path). 3) Find the common elements and apply ls -lah

A filthy way to do it. It is recommended only if you are desperate :>

Also you may find useful find . -type d -print0 {} \; | xargs ls -lah

share|improve this answer
Don't use ls, use GNU find's -printf option, it gives you full control over the print format. – Gilles Aug 20 '10 at 10:43
i did it because it's the typical format that you can pass to xargs. in any case, thanks for the info :> – Nikolaidis Fotis Aug 20 '10 at 11:18
Yes, I guess that's the way to go... Combined with weeheavy's usefull awk '{print "chown "$3":"$4,$8}' for restore. – Drasko Aug 20 '10 at 12:30

You can use the getfacl tool (part of the acl package) to dump and restore both normal unix permissions and acls:

Use getfacl -R to dump the acls out into a file, and use setfacl --restore=file to restore them:

       Restore a permission backup created by 'getfacl -R' or similar. All
       permissions of a complete directory subtree are restored using this
       mechanism.  If the input contains owner comments or group comments,
       setfacl attempts to restore the owner  and  owning  group.  If  the
       input contains flags comments (which define the setuid, setgid, and
       sticky bits), setfacl sets those three bits accordingly; otherwise,
       it  clears  them.  This  option  cannot be mixed with other options
       except '--test'.

This works even if you don't have acls set - the tool will dump and restore standard unix fs permissions. It will also work if your filesystem doesn't have acl support turned on (it's a non-default mount option for most filesystems still)

share|improve this answer

Solaris has an advantage here, as it has a nice command called pkgproto.

But you could use something like

find /home/elao/ -type d | xargs ls -lnd | awk '{print "chown "$3":"$4,$8}'
share|improve this answer
ls -lnd lists files with UID ownership which I want to avoid, because all UIDs will be changed after upgrade due to the idmap backend change. That awk will do the job for restoring with one little change: awk '{print "chown "$3":"$4,$NF}' (on Gentoo filename column is not 8th, but 9th). Thanks for the quick response! – Drasko Aug 20 '10 at 12:35
Ah I see now why you don't want UIDs. You're welcome. – weeheavy Aug 20 '10 at 13:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.