Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

chgrp

Change the group of files and directories.

Niveau
RHCSA-examen
Groep
Rechten
Root nodig
Voor wijzigingen
Pakket
coreutils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

chgrp GROUP FILE sets the group. root can set any group. A normal user can change the group of an own file, but only to a group he is a member of.

It is the same as chown :GROUP FILE.

Zo schrijf je het

chgrp [OPTION]... GROUP FILE...
chgrp [OPTION]... --reference=RFILE FILE...

Opties 14

Meest gebruikt

-R, --recursive
Change the whole tree.
-v, --verbose
Report every file.
-c, --changes
Report only changes.
-f, --silent, --quiet
Do not show most errors.
-h, --no-dereference
Change a link itself.
--dereference
Change the target of a link (default).
--reference=RFILE
Use the group of RFILE.
--preserve-root
Refuse to work recursively on /.
--no-preserve-root
Do not treat / special (default).
-H
With -R: follow a link given on the command line.
-L
With -R: follow every link to a directory.
-P
With -R: follow no links (default).
--help
Show help.
--version
Show the version.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Give a folder to a team

    chgrp sales /srv/sales

    Combine with chmod 2770 for a shared folder.

  2. 2Change a whole tree

    chgrp -R sales /srv/sales

    All files and folders inside.

  3. 3As a normal user, for your own file

    chgrp sales plan.txt

    Works only if you are in sales.

  4. 4Error when you are not a member

    chgrp wheel plan.txt
    chgrp: changing group of 'plan.txt': Operation not permitted

    Join the group first.

  5. 5Show what changed

    chgrp -Rc sales /srv/sales

    Lists only files that got a new group.

  6. 6Use the group of another file

    chgrp --reference=/srv/sales /srv/sales/import.csv

    Same group as the folder.

  7. 7Fix files after a group GID change

    find /srv -gid 3000 -exec chgrp -h sales {} +

    Files with the old number get the group name again.

  8. 8Group of the web logs for a log team

    chgrp -R logreaders /var/log/httpd; chmod -R g+rX /var/log/httpd

    Read access without root (check that the logs rotate with the same group).

  9. 9Group for a config read by a service

    chgrp nginx /etc/pki/tls/private/site.key; chmod 640 /etc/pki/tls/private/site.key

    The service reads the key; others cannot.

  10. 10Find files of a group (audit)

    find /srv -group sales -ls

    Shows everything the group owns.

Exitcodes

0Done.
1Error.