Re: chmod, chgrp and symlinks

From: Kasper Dupont (kasperd@daimi.au.dk)
Date: 02/04/03


From: Kasper Dupont <kasperd@daimi.au.dk>
Date: Tue, 04 Feb 2003 09:26:19 +0100

Ramazan Jah-Far wrote:
>
> use
> find $dir -type f -name *.mp3 -exec chmod 640 {} \;

For faster execution you could make use of xargs:
find $dir -type f -name '*.mp3' -print0 | xargs -0 chmod 640

and to prevent chmod on hardlinks you could use:
find $dir -type f -links 1 -name '*.mp3' -print0 | xargs -0 chmod 640

Of course there might still be the problem with race
conditions. Any good ideas on how to deal with that?

-- 
Kasper Dupont -- der bruger for meget tid på usenet.
For sending spam use mailto:aaarep@daimi.au.dk
for(_=52;_;(_%5)||(_/=5),(_%5)&&(_-=2))putchar(_);


Relevant Pages

  • Re: [opensuse] Script problem
    ... Will set all directories to chmod 755 ... will set all regular files to perm 644 ... Your problem is most likely the spaces in the filenames; ... See the man pages for xargs and find for more explanations. ...
    (SuSE)
  • Re: [opensuse] /bin/rm: Argument list too long
    ... They used xargs to process a list of unpredictable size - good! ... ...Then they go on in the same script to use chown and chmod in backwards order such that chown undoes what chmod did. ... then any files with spaces in the names will look like seperate files to whatever command you ran with xargs. ...
    (SuSE)
  • Re: [opensuse] /bin/chmod: Argument list too long - how long is too long?
    ... It's whole point is to coalesce commands as much as the shell and the kernel will allow, because iterating through huge lists one file or one item at a time is slow and inefficient a lot of times. ... It's true that some versions of find do, or can coalesce the arguments sort of like having xargs built-in, but that is the exception not the rule and shouldn't be relied on. ... What the original command was really running was several big sudo commands, where really it's more expected to run several big chmod or other direct commands. ...
    (SuSE)
  • Re: changing permissions of files in directories
    ... >> Is the version with xargs better, ... > The version with xargs is much better: it runs a single instance of ... > than running a separate instance of chmod for every file. ... version spawns find and then a chmod process for every file that ...
    (Debian-User)
  • Re: changing permissions of files in directories
    ... >> Is the version with xargs better, ... > than running a separate instance of chmod for every file. ... > of the command line. ... > behave this way or can be made to behave this way. ...
    (Debian-User)