Re: chmod
> > And if anyone's in a 'splaining mood, here's another one: how do you set
> > all files so that the group permissions match the user permissions?
>
> This one is tougher, I think. You could write
> such a utility pretty easily in C using the "stat()" function, but
> even though it's simple it seems like over kill. Gotta be a better
> way.
Doing it in C (untested code):
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char * argv[]) {
struct stat * buf = (stat *) malloc(sizeof(stat));
int retval;
mode_t new_mode;
mode_t to_add;
if (argc != 2) exit(1);
retval = stat(argv[1],buf);
if (retval != 0) exit(1);
new_mode = buf->st_mode;
/* NOTE: This gives the group >= permisions, change to suit */
if (buf->st_mode & S_IRUSR) new_mode &= S_IRGRP;
if (buf->st_mode & S_IWUSR) new_mode &= S_IWGRP;
if (buf->st_mode & S_IXUSR) new_mode &= S_IXGRP;
chmod(argv[1],new_mode);
exit(0);
}
Using scripts:
#!/bin/sh
ls -l | fgrep $* | cut -c 2-4 | tr -d '-' | xargs --replace chmod g={} $*
find . -name \* -exec script.sh {} \;
Open invitation for any perl monk...
Corrin
--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Reply to:
- Follow-Ups:
- Re: chmod
- From: Colin Watson <cjwatson@debian.org>
- References:
- chmod
- From: Daniel D Jones <ddjones@riddlemaster.org>(by way of Daniel D Jones <ddjones@riddlemaster.org>)
- Re: chmod
- From: "Gary Hennigan" <glhenni@sandia.gov>