Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
I have to clone files permissions and ownership for entire /usr directory. I can't just copy files because the source and the destination files built with different cflags and different options. I just need to clone permissions on built files.
There is --reference=RFILE option for chown/chmod commands, but I don't know how to use these command recursively with that option.
I notice you changed name of the target path between your initial post and your final one.
Also you may have missed that I said you should cd to the source directory, /usr, before running the find. The syntax I wrote worked properly when I did a test here. "find ." means "find from this location so if you're sitting in /usr it would do the find there but wouldn't include the "/usr" in the output. Either way should work.
Use chown -h so it also changes ownership of symlinks. (Otherwise follows the symlinks, that can be dangerous in some scenarios.)
Also, quote variables in command arguments.
Code:
for file in $(cd /usr && find .)
do chown -h --reference="$file" /media/usr/"$file"
done
@MensaWater
"find ." returns relative filename, it starts with "./" symbols.
In fact, related to the current directory, it gives right filename, but when "./" prepended with the destination directory (like /media/usr) it gives wrong file name: "/media/usr/./some_sub_dir" with the dot in the middle.
I posted above the sample of erroneous filename
So, to fix this error we need to get absolute file name like "/usr/some_sub_dir" in $file variable which being concatenated with "/media" gives correct path: "/media/usr/some_sub_dir" without any dot in the middle
And "find /usr" returns absolute filename.
This case "cd /usr" command is unnecessary.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.