Discussion Locked

Need help restoring mode and group info.

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

A script I wrote inadvertently issued errant chmod and chgrp commands recursively on a large directory. I have a similar directory on another unix machine which has not been damaged.

I can't just copy the files over and recovery from backup is not doable.

I can see how a script could use find to capture the permissions and groups from the unmodified files and create a second script that would issue appropriate chmod and chgrp commands on the damaged ones, but I'm not comfortable with thes, S, t, T bits, and issues such as symbolic links.

Does anyone have a script or other method of copying the group and file modes of a set of files, including sub-directories, symbolic links, etc. and applying them to identically named objects?
Thanks,
Jeff

3 replies

by dbunda

I would try removing or moving the "wrong" files out of the way, and simply ftp-ing the files over from the other place. Other ways include doing a cpio command that has options to preserve permissions. A command like this can be used to make a quick copy from one files system to another as long ats they are both mountable on the sme machine,
cd fromdir; tar cf - . | (cd todir; tar xf -)

by Member 36074154

Thanks for the answer, but I'm afraid it doesn't help. As I specified in my question, copying the unmodified files over the damage ones is not an option. The original data must stay in place, with just the permission modes and group ownership corrected.

Actually, I am going to close this question. We have decided to rebuild the operating system - it was due anyhow. Yes, the damage was done at the root level, by root ... I won't make that mistake again!

This discussion is closed to new replies.