Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kotfu/chogm
Change the owner, group and mode of both files and directories with one command
https://github.com/kotfu/chogm
Last synced: 8 days ago
JSON representation
Change the owner, group and mode of both files and directories with one command
- Host: GitHub
- URL: https://github.com/kotfu/chogm
- Owner: kotfu
- License: mit
- Created: 2013-01-03T05:33:47.000Z (about 12 years ago)
- Default Branch: main
- Last Pushed: 2020-08-25T21:23:19.000Z (over 4 years ago)
- Last Synced: 2023-04-05T09:10:44.876Z (almost 2 years ago)
- Language: Python
- Homepage:
- Size: 19.5 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
chogm
-----Change the owner, group and mode of some files with a single command
Usage
-----chogm [OPTIONS] files_spec directories_spec file [file file ...]
-R, --recursive recurse through the directory tree of each file
-v, --verbose show progress
-h, --help display this usage message
file_spec owner:group:perms to set on files
directory_spec owner:group:perms to set on directories
file one or more files to operate on. Use '-' to
process stdin as a list of filesfile_spec tells what owner, group, and permissions should be given to any
files. Each of the three elements are separated by a ':'. If a value is
not given for a particular element, that that element is not changed on
the encountered files.directory_spec works just like files_spec, but it is applied to
directories. If any element of directory_spec is a comma, the value of that
element will be used from file_specExamples
--------### Simple
chogm www-data:www-data:644 -:-:755 /pub/www/*
Change all files in /pub/www to have an owner and group of www-data, and
permissions of -rw-r--r--. Also change all directories in /pub/www/ to
have an owner and group of www-data, but permissions of -rwxr-xr-x. This
is equivilent to the following shell commands:$ chown www-data:www-group /pub/www/*
$ find /pub/www -maxdepth 1 -type f | xargs chmod 644
$ find /pub/www -maxdepth 1 -type d | tail -n +2 | xargs chmod 755### More Complex
chogm -R :accounting:g+rw,o= :-:g=rwx,o= /mnt/acct
Change the group of all files in /mnt/acct to be accounting, and make
sure people in that group can read, write, and create files anywhere in
that directory tree. Also make sure that the hoi palloi can't peek at
accounting's files. This is the same as doing:$ chgrp -R accounting /mnt/acct
$ find /mnt/acct -type f -print | xargs chmod g+rw,o=
$ find /mnt/acct -type d -print | xargs chmod g=rwx,o=### Using stdin
find ~/src -depth 2 -type d -print | grep -v '/.git$' | chogm -R :staff:660 :-:770 -
Assuming your ~/src directory contains a bunch of directories, each with
their own git project, change all those files to have a group of staff
and permissions of -rw-rw---- and all the directories to also have a
group of staff but permissions of -rwxrwx---. While doing all of that,
don't change the permissions of any of the files inside of .git
directories.Requirements
------------This script uses the operating system commands xargs, chmod, chgrp, and
chmod to do it's work. It also uses the python multiprocessing module from
the standard library which was added in python 2.6, so it won't work with
python versions earlier than that. It works in python 2.7 and 3+.Exit Status
-----------0 - everything OK
1 - some operations not successful (ie permission denied on a directory)
2 - incorrect usageLicense
-------Check the LICENSE file. It's the MIT License, which means you can do whatever you want, as long as you keep the copyright notice.