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.
Hey, i have to folders /home/ and /backup/ Backup is just has the same folders as the one in from /home/ so /home/jacky and /backup/jacky but they all contain different content and files.
The folders from /home/ has user and group permissions set to it, and the ones from /backup/ doesnt.
So now i need a script that set the user and group permissions for every folder from backup to the same from /home/.
Any help?
Just in plain words, with correct commands will help me out alot.
Thx
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
Hm, what I would do is probably
Code:
cd /home; find . -type d -exec chmod --reference='{}' ';' ../backup/'{}'
Explanation:
find is to list or uniformly process all the objects meeting a certain criteria.
find . : means that you want to traverse current directory (you are in /home , and relative directory paths with respect to home/ can be used as relative paths with respect to backup/)
-type d : means you are only interested in directories.
-exec : you do not want to simply print files, you want a command executed on them. In the command (all the following arguments) any occurence of {} (we have to escape it from shell, so '{}') is replaced with file name, and the command must be terminated with ; (again, shell would like to interpret it as an end-of-command and eat it, so ';')
chmod --reference=file another_file : change permissions of the second file, trying to reproduce permissions of the first file.
man find, man chmod will give you more information.
cd /home; find . -type d -exec chmod --reference='{}' ';' ../backup/'{}'
Explanation:
find is to list or uniformly process all the objects meeting a certain criteria.
find . : means that you want to traverse current directory (you are in /home , and relative directory paths with respect to home/ can be used as relative paths with respect to backup/)
-type d : means you are only interested in directories.
-exec : you do not want to simply print files, you want a command executed on them. In the command (all the following arguments) any occurence of {} (we have to escape it from shell, so '{}') is replaced with file name, and the command must be terminated with ; (again, shell would like to interpret it as an end-of-command and eat it, so ';')
chmod --reference=file another_file : change permissions of the second file, trying to reproduce permissions of the first file.
man find, man chmod will give you more information.
thx for the reply, but however, im not good at this, so i just copied your code into mine command line. Not sure if i need to change anything to your script. There like 380 folders so doing them manually is not an option. So i runned youre script and it says:
find: pathnames must first have expressions
Use: find [-H] [-L] [-P] [path..] [expression]
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
Hm, I typed must be terminated with ; in explanation and messed it up in the command. ';' should be the last parameter to find, not one-before-last.
But in general, if you have a sample, an explanation and references, it is usually better to try to verify explanation against manual page references and make sure that you understand the command a complete stranger offers you to run in /home/. I do hope that on LQ a post with hidden destructive commands get deleted, but it can be spotted too late..
ok thx mate, now it runs, but it says for my files
chmod: cannot get acces to ../backup/./jacky file/or folder does not excist
chmod: cannot get acces to ../backup/./dirk file/or folder does not excist
chmod: cannot get acces to ../backup/./tommy file/or folder does not excist
.....
Is it giving error to the backup/./dirk? or is it giving error to ../backup? my backup folder is just /backup/jacky /backup/dirk and so on, if this is any help?
[edit]
if i change the script to:
cd /backup; find . -type d -exec chmod --reference='{}' ';' ../home/'{}'
it does run?
So what am i doing here? I need to set every folder in backup to the same properties from /home/?
Cheers
Last edited by zerocool22; 05-27-2008 at 04:01 AM.
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
Well, it should. I thought you have mirror directory structure. ';' must be moved back to the end; if you work in /backup, you want to chmod '{}' and use /home/'{}' as reference, not the other way round. Also with most mass-execution commands it is good to run it with the mass command prepended by "echo", i.e. replace chmod with echo chmod. If you believe that the commands printed will be correct (it is much easier to verify a single chmod than a complicated find), run without echo.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.