ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
for i in $( ls /backup ) ; do
if [ -d /backup/$i ]; then
chown --reference=/home/$i /backup/$i
else
echo ls /backup/$i
fi
for j in $( ls /backup/$i ) ; do
if [ -d /backup/$i/$j ]; then
chown -R --reference=/home/$i/$j /backup/$i/$j
I presume you have a series of user directories under /home and you want the permissions of the directories in /backup to match those. If that is the case, then the following might be more suitable:
Code:
for dir in /home/*; do
chown -R --reference=$dir /backup/$(basename $dir)
done
I have /home/ folders with user/group properties on them, now i need to match them to my /backup/ folders which contain the same folders, but different content.
one last question about this, cause im still having some troubles, so the home folder properties are getting copied to backup nicely. But sometimes /home/ has a folder that doesnt excist in /backup/ like for example /home/tompie but there is no /backup/tompie so the properties cant be copied to backup. So i want to list all folders that do excist on home but not on backup.
I thought i was doing that by saying if [ -d /backup/$i ]; then
else
echo ls /backup/$i
one last question about this, cause im still having some troubles, so the home folder properties are getting copied to backup nicely. But sometimes /home/ has a folder that doesnt excist in /backup/ like for example /home/tompie but there is no /backup/tompie so the properties cant be copied to backup. So i want to list all folders that do excist on home but not on backup.
I thought i was doing that by saying if [ -d /backup/$i ]; then
else
echo ls /backup/$i
But he doesnt list any to the screen??
All that snippet of code says is, if /backup/$i is a directory, then chown it, otherwise, list its contents. It doesn't check to see if it's present in /home too. To do that, you might do something like:
Code:
for dir in $(ls /home/); do
if [[ -d /home/$dir && -d /backup/$dir ]]; then
do whatever you want
else
echo some error message
fi
done
That will check to see if a directory exists in both /home and /backup, and if so, then you can run whatever command you want on both the files. If it only exists in one (either /home or /backup), then you can print out some error message.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.