LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 01-27-2011, 03:47 PM   #1
JohnE1
Member
 
Registered: Jun 2007
Location: Houston, TX
Distribution: Fedora, CentOS, Ubuntu
Posts: 66

Rep: Reputation: 16
Conditionally change group ID


I have a set of files that have a group ID number where no group exists in the system with that number.

I want to recursively read the group IDs of all (including hidden) files in the current and sub-dirs, test each file's group ID, and if it equals the search GID number, I want to execute a chgrp command on that file.

Anyone have an admin script already made for this task?

Thanks in advance!
 
Old 01-27-2011, 04:03 PM   #2
tommylovell
Member
 
Registered: Nov 2005
Distribution: Raspbian, Debian, Ubuntu
Posts: 380

Rep: Reputation: 103Reputation: 103
'cd' to the directory that you want to start in.

Then try
Code:
find . -group xxxx -exec ls -l {} \;
where xxxx is the "bad" GID. This will show you all of the files with that GID.

If you're happy with the list
Code:
find . group xxxx -exec chgrp yyyy {} \;
to change xxxx to yyyy.

Or, if you want to confirm each one
Code:
find . group xxxx -ok chgrp yyyy {} \;
which could be tedious...
 
Old 01-27-2011, 05:29 PM   #3
JohnE1
Member
 
Registered: Jun 2007
Location: Houston, TX
Distribution: Fedora, CentOS, Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 16
Thanks, Tommy! I'll give that a try and post back here.
 
Old 01-27-2011, 07:09 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
When I've had the problem, I've just created a group with the "unassigned" number, and proceeded from there. But the find solution should suggested by johnE1 will also work.
 
Old 01-27-2011, 09:16 PM   #5
JohnE1
Member
 
Registered: Jun 2007
Location: Houston, TX
Distribution: Fedora, CentOS, Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 16
Lightbulb SOLVED: Conditionally change group ID

Tommy, your examples were very helpful. Thank you!

Here's what I ended up using.

To verify find results:
find . group xxxx -print0 | xargs -0 ls -AL

To change group of each file (and sub-directory) found:
find . group xxxx -print0 | xargs -0 chgrp yyyy

NOTE: Those are zeroes (0's).
 
Old 01-27-2011, 09:34 PM   #6
tommylovell
Member
 
Registered: Nov 2005
Distribution: Raspbian, Debian, Ubuntu
Posts: 380

Rep: Reputation: 103Reputation: 103
Cool. Your way is an excellent alternative, especially (I think) when there are a very large number of files to change.
As the Perl people say, "Tim Toady" - There's More Than One Way To Do It (TMTOWTDI).

Last edited by tommylovell; 01-27-2011 at 09:35 PM.
 
  


Reply



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] [Makefile] Run command conditionally in target? littlebigman Programming 2 11-25-2010 05:09 PM
Secondary group users need to change the file permissions of primary group files? sunnybmv Linux - Newbie 3 12-10-2009 04:57 PM
Conditionally Setting up Different Network Connections Based on Available Networks c4onastick Linux - Networking 1 09-07-2009 02:23 PM
Postfix: appending to outbound mail conditionally jgombos Linux - Server 0 03-23-2007 08:45 PM
Conditionally mounting nfs shares eagle862 Linux - Networking 1 11-02-2004 11:46 PM

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

All times are GMT -5. The time now is 07:52 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
Open Source Consulting | Domain Registration