LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-16-2017, 02:38 PM   #1
xander85
LQ Newbie
 
Registered: Dec 2017
Posts: 1

Rep: Reputation: Disabled
Delete removed user group from group file with awk


hello im a complete beginner in programming much less awk programming

im trying to delete removed users groups from the group file, basically a script that searches the passwd file then checks the group file. if uid dont match then delete the group
 
Old 12-16-2017, 07:02 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,331

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546
that is not something a new user to linux would want to have a "script" do

now if this is an office and many people share the computers , then maybe

but i would still want to remover usergroups by hand

a minor bug in a script might do some really odd things
 
1 members found this post helpful.
Old 12-16-2017, 07:21 PM   #3
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,890

Rep: Reputation: 1674Reputation: 1674Reputation: 1674Reputation: 1674Reputation: 1674Reputation: 1674Reputation: 1674Reputation: 1674Reputation: 1674Reputation: 1674Reputation: 1674
You could use this command to get a list of GIDs that have no matching entry in /etc/passwd
Code:
join -v 2 <(cut -d ":" -f4 /etc/passwd | sort -u) <(cut -d ":" -f3 /etc/group | sort -u)
To edit, I would use 'vigr'. This would need to be done thoughtfully, as there are likely to be unmatched system groups that you should still retain.

Last edited by allend; 12-16-2017 at 07:52 PM.
 
1 members found this post helpful.
Old 12-18-2017, 07:33 AM   #4
fatmac
Senior Member
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: AntiX
Posts: 2,252

Rep: Reputation: Disabled
Be aware, there are groups that the system uses that you may think nothing uses.
 
1 members found this post helpful.
Old 12-18-2017, 08:36 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,078

Rep: Reputation: 675Reputation: 675Reputation: 675Reputation: 675Reputation: 675Reputation: 675
Quote:
Originally Posted by xander85 View Post
hello im a complete beginner in programming much less awk programming

im trying to delete removed users groups from the group file, basically a script that searches the passwd file then checks the group file. if uid dont match then delete the group
And for files in disk owned by that group?
 
1 members found this post helpful.
Old 12-20-2017, 11:51 AM   #6
MadeInGermany
Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 694

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
You can list the empty groups with
Code:
awk -F: 'NR==FNR { s[$4]; next } (!($3 in s) && $4=="")' /etc/passwd /etc/group
This has two conditions, not used in passwd (primary group) and no user listed (secondary group)
As was already said, it is not safe to delete all empty groups!
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] I when I add a user to a group, something removed that user... trist007 Ubuntu 1 02-22-2016 10:41 AM
(RHEL5) Not able to delete/add user : unable to lock group/password file sakshi.garg23 Linux - Newbie 32 11-10-2014 10:04 PM
[SOLVED] user removed from one group can still get that group's permission LanFan.BlueSailor Linux - Security 11 08-23-2012 12:32 AM
Group permissions: user can't access 770 directory even though a member of group jm34003 Linux - Security 13 05-16-2012 02:03 PM
[SOLVED] How to delete a user from group? rammohantv Linux - Newbie 4 01-29-2010 12:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration