How to chmod multiple files based on multiple --reference files ?
Hi Linux pro's,
OK, so I made a mistake while trying to move /usr, /var and /tmp to separate partitions (my single / partition was getting filled up). For some daft reason I copied (using cp -Rp) these dirs to an external hdd which was formatted as a ntfs filesystem, and then copied them back to the new partitions, edited fstab accordingly etc. etc. and deleted the original dirs from /. (yes I booted from a live-cd to do this) So after rebooting I realized all the permissions was changed on these new partitions by the fact that it was copied first to a ntfs filesystem and then back to the new partitions. Lots of error messages etc. etc. which I managed to fix here and there but the system is still a bit wonky with some stuff not working. Anyway, luckily some sanity prevailed and I backed up the original / directory which I subsequently restored (and mounted) on a loop image on another empty partition on my system. Now I would like to change the permissions and owners of all files in /usr, /tmp and /var according to the restored original files in the mounted image file - perhaps using chmod --reference, although doing this one by one would be extremely time-consuming. Question 1: Is there a way to do this perhaps recursively like using chmod -R --reference on the directories? Question 2: If yes, how would I go about it ? I suppose I could just boot from a live-cd and copy everything again (using cp -a or perhaps tar ?) in their respective new partions from the restored image file, but I am not sure if my nerves would handle this procedure again... Many thanks in advance ! |
How to chmod multiple files based on multiple --reference files ?
as i understnd ur theory & question better way to use * option,
#chmod <permissions> * |
Thanks for the quick reply.
I am not sure I understand your solution. Are you suggesting I should try something like: chmod -R --reference=/mnt/res/tmp/tmp/* /tmp/* ? Cheers. |
Wouldn't it be easier to just copy over the files with the correct permissions again?
|
Files in /usr, /tmp and /var may be owned by different users and have different access permissions. This should work:
Code:
find /mnt/res/tmp/ -printf "%U %G %m %p\n"|sed -e "s|/mnt/res/tmp||g"|while read LINE; do |
Yes it seems it would, although I suffer from a disease called "like to complicate life for myself".
Also, I am intrigued by the possibilities that can be accomplished by using clever code and perhaps learn something in the process, so I thought I'd delay copying everything again and search for an alternative solution. But perhaps not. Thanks anyway ! Cheers. |
Thanks unSpawn !
Wow, the echo definitely looks sane from what I can see. I'll do the actual apply tonight using a live cd, and let you know. -there was a small typo with a duplicated ";" in your code above, but easily removed. Being a complete bash code newbie, I am for sure going to learn much from your code above once I have figured out what it means exactly. Cheers. |
Quote:
Quote:
Code:
find /mnt/res/tmp/ |
OK, so I tried it and for some reason it did not work right (permissions changed but not reflecting the reference originals), so I did it the easy way - copying everything again (by using 'cp -a' from a live-cd).
I think there may have been some files that were added or removed from the original files or some bug that slipped in somewhere, as it seems the code above works well. Perhaps I did not inspect the echo output as well as I should have. Anyway no harm done. Thanks for the code breakdown above - I am a wiser man today, but clearly has still lots to learn. Cheers. |
Quote:
Quote:
Quote:
|
:-)
Actually I did preserve the output: chown: cannot access `': No such file or directory chmod: cannot access `': No such file or directory chown: cannot dereference `usr/lib/i386-linux-gnu/libOSMesa.so': No such file or directory chmod: cannot operate on dangling symlink `usr/lib/i386-linux-gnu/libOSMesa.so' chown: cannot dereference `usr/share/java/werken.xpath.jar': No such file or directory chmod: cannot operate on dangling symlink `usr/share/java/werken.xpath.jar' chown: cannot dereference `usr/share/bug/vlc-plugin-pulse': No such file or directory chmod: cannot operate on dangling symlink `usr/share/bug/vlc-plugin-pulse' chown: cannot dereference `usr/share/bug/vlc-nox': No such file or directory chmod: cannot operate on dangling symlink `usr/share/bug/vlc-nox' chown: cannot dereference `usr/share/bug/vlc': No such file or directory chmod: cannot operate on dangling symlink `usr/share/bug/vlc' chown: cannot dereference `usr/share/bug/libvlc5': No such file or directory chmod: cannot operate on dangling symlink `usr/share/bug/libvlc5' chown: cannot dereference `usr/share/bug/vlc-plugin-notify': No such file or directory chmod: cannot operate on dangling symlink `usr/share/bug/vlc-plugin-notify' chown: cannot dereference `usr/share/dict/words': No such file or directory chmod: cannot operate on dangling symlink `usr/share/dict/words' chown: cannot dereference `usr/share/doc/kde/HTML/en_GB/kcontrol/kalarmd/common': No such file or directory chmod: cannot operate on dangling symlink `usr/share/doc/kde/HTML/en_GB/kcontrol/kalarmd/common' chown: cannot dereference `usr/share/doc/kde/HTML/en_GB/knotes/common': No such file or directory chmod: cannot operate on dangling symlink `usr/share/doc/kde/HTML/en_GB/knotes/common' chown: cannot dereference `usr/share/doc/kde/HTML/en_GB/kleopatra/common': No such file or directory chmod: cannot operate on dangling symlink `usr/share/doc/kde/HTML/en_GB/kleopatra/common' chown: cannot dereference `usr/share/doc/kde/HTML/en_GB/knode/common': No such file or directory chmod: cannot operate on dangling symlink `usr/share/doc/kde/HTML/en_GB/knode/common' chown: cannot dereference `usr/share/doc/kde/HTML/en_GB/kalarm/common': No such file or directory chmod: cannot operate on dangling symlink `usr/share/doc/kde/HTML/en_GB/kalarm/common' So I guessed these were the files that I had to change via a live-cd as they were probably open during the procedure likw you said (being dangling symlinks). Except perhaps the first two lines... not sure what that was. I promptly rebooted and did a 'sudo apt-get update' (just to check), only to find a message saying the sudoers list being open for anybody to write/change or something to that effect. "Eish!" (to use some local slang expressing disappointment, dissatisfaction or regret, even alarm sometimes). So I figured I should just redo the copy procedure but in the right way this time. Don't want anybody to get access to my top secret and highly classified files on my system if you know what I mean :-) From the little background I have with R code, I wonder if perhaps a clause in your code above to first match filenames before changing permissions/owners would have been better (although I have no idea if this would be feasible or possible). Cheers. |
All times are GMT -5. The time now is 11:18 PM. |