الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

newgrp

Start a new shell with another primary group — useful right after you were added to a group.

المستوى
لينكس اليومي
المجموعة
المستخدمون والمجموعات
يحتاج root
لا
الحزمة
shadow-utils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

When an admin adds you to a group, your running sessions do not have it yet. newgrp GROUP starts a new shell in which GROUP is your primary group (new files get this group) and the group is active.

If you are not a member, newgrp asks for the group password (if one is set). exit returns to the old shell.

طريقة الكتابة

newgrp [-] [GROUP]

الخيارات 2

الأكثر استخدامًا

GROUP
The group to use. Without a name: your primary group from the account.
-
Start like a new login (reset the environment).

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Use a new group without a new login

    newgrp webadmins
    id -gn
    webadmins

    exit to go back.

  2. 2Create files with a team group

    newgrp sales
    touch report.txt; ls -l report.txt
    -rw-r--r--. 1 anna sales 0 Oct 25 10:12 report.txt

    New files get the primary group sales.

  3. 3Check the active groups before and after

    id -Gn; newgrp webadmins; id -Gn

    The new shell has the group.

  4. 4Go back to the normal group

    exit

    Leaves the newgrp shell.

  5. 5Start as a new login

    newgrp - sales

    Clean environment, like a new login.

  6. 6Run one command with a group (sg)

    sg sales -c 'touch /srv/sales/plan.txt'

    sg = newgrp for one command.

  7. 7Join with a group password

    newgrp projectx
    Password:

    Works only if a group password was set (rare).

  8. 8In a script after adding a user to docker or podman groups

    newgrp libvirt

    For example after usermod -aG libvirt $USER to use virsh without a new login.

  9. 9Check the group of new files

    umask; newgrp sales; touch x; stat -c '%G' x
    sales

    Shows which group new files get.

  10. 10Best alternative: log in again

    exit

    A new login gives all groups at once, not only one.

انتبه

  • newgrp starts a new shell; your old variables and history are not in it.
  • A setgid folder (chmod g+s) is often a better way to give files a team group.

الملفات

/etc/group, /etc/gshadow
Members and group passwords.

رموز الخروج

0Done (exit code of the shell).
1Not allowed or the group does not exist.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man newgrp