Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 am about to modify the file ownership recursively in a filesystem that uses ACLs. Because it is my backup disk, I thought I'd solicit comments on the script before I run it.

# Replace Foobar, Bob, and Brand.
PREFIX="/Volumes/Foobar-Time-Machine/Backups.backupdb/Bob’s MacBook"

for dir in "${PREFIX}"/*/
    chmod -R -a "group:everyone deny chown" "${PREFIX}${dir}${SUFFIX}${USER}"
    chown -R $USER "${PREFIX}${dir}${SUFFIX}${USER}"
    chmod -R =a# 1 "group:everyone deny add_file,delete,add_subdirectory,delete_child,writeattr,writeextattr,chown" "${PREFIX}${dir}${SUFFIX}${USER}"

Do you spot a disaster waiting to happen? The first chmod is meant to remove minimal ACL and the second is meant to restore it. Can the script be made safer? Needless to say, the script would be run as sudo.

share|improve this question

migrated from stackoverflow.com Mar 11 '12 at 13:59

This question came from our site for professional and enthusiast programmers.

For readability, consider changing $PREFIX$dir$SUFFIX$USER to ${PREFIX}${dir}${SUFFIX}${USER}. Rewrite it to use ksh, or bash, and you'll be better off (read grymoire.com/Unix/CshTop10.txt for more info). Other than that, you seem to only be chowning backups for bob to bob, and denying the everyone group access to those files. I don't see any problems with that, as those files would be owned by bob on a restore anyways. – Tim Kennedy Mar 11 '12 at 20:28
Done. Thanks. The problem is not so much who owns the files after a restore (I'm comfortable with chwon-ing on my working drive). The problem is that the history is invisible (through ownership protection). Changing ownership on the backup drive takes the risk of corrupting the format used and making the backups unusable. – Calaf Mar 22 '12 at 18:02

I would use find with '-print0' and xargs... ACL are cryptic, better not to use them.

share|improve this answer
Cryptic or not, ACLs must be tackled, with find-to-xargs or directly. – Calaf Mar 22 '12 at 18:33
You shouldn't make a statement such as "don't use ACLs" without offering an alternative. Standard UNIX permissions are not a valid alternative. – jordanm Mar 17 '13 at 23:23
They are valid in 99%, just more work with groups. – Jiri Xichtkniha Mar 19 '13 at 16:50

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.