Using the "find" command to look for multiple UID's


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using the "find" command to look for multiple UID's
# 8  
Old 03-26-2013
Quote:
Originally Posted by westmoreland
Fine question Don. And good point. In this case, I believe the auditor is looking to see exactly what the permission bits are set to for files with specific users and groups (haven't included that part yet). Ultimately, I think he actually wants to see the ACL's (if any) associated with those particular files.
You will usually find that this forum can provide much better help and provide it sooner, if you state all of the requirements up front. When you hide some of the requirements (or add on new requirements after an initial question has been answered) you waste a lot of time for the volunteers who are trying to help you.
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 03-26-2013
Thanks for all the input y'all. I think I've found a reasonable solution. I ended up with a nested for statement that looks like this:



for p in /u01 /u02 /home; do for i in `find $p -type f -uid +100`; do getfacl $i; done; done >> output.txt



I entered this on the command line. It loops through the directories /u01, /u02 and /home using the find command to search those directories for regular files (-type f) with uid greater than 100 (-uid +100). It then uses the results of that find command to get the ACL for each file found (getfacl $i) and send the output to ouptput.txt
# 10  
Old 03-26-2013
Quote:
Originally Posted by westmoreland
Thanks for all the input y'all. I think I've found a reasonable solution. I ended up with a nested for statement that looks like this:



for p in /u01 /u02 /home; do for i in `find $p -type f -uid +100`; do getfacl $i; done; done >> output.txt



I entered this on the command line. It loops through the directories /u01, /u02 and /home using the find command to search those directories for regular files (-type f) with uid greater than 100 (-uid +100). It then uses the results of that find command to get the ACL for each file found (getfacl $i) and send the output to ouptput.txt
If that nested for statement works for you, the following will do exactly the same thing much more efficiently and faster:
Code:
find /u01 /u02 /home -type f -uid +100 -exec getfacl {} + >> output.txt

# 11  
Old 03-26-2013
Haha, yeah I do tend to make things more complicated sometimes. That' s working much better. One question though, the "+" sign before the redirectors, I don't understand that one. I got an error and had to change it from
Code:
{} + >>

to
Code:
{} /; >>

.
# 12  
Old 03-26-2013
Quote:
Originally Posted by westmoreland
Haha, yeah I do tend to make things more complicated sometimes. That' s working much better. One question though, the "+" sign before the redirectors, I don't understand that one. I got an error and had to change it from
Code:
{} + >>

to
Code:
{} /; >>

.
Please try the command:
Code:
man find

and look at the description of the -exec primary. The + tells find to pass multiple filenames to getfacl instead of invoking getfacl once for each found filename.

Note also that using /; instead of + or \; should have resulted in a diagnostic from find saying something like:
Code:
find: -exec: no terminating ";" or "+"

Please show us the exact command line you entered and the exact diagnostic message(s) that find produced.

On a Solaris system, using \; instead of + should produce the same results, but consume a lot more system resources doing so.
# 13  
Old 04-01-2013
HP-UX 11.23 find and SLED 11 find have a bug with + so \; is safer anyway.

\( -user user1 -o -user user2 \)
searches for user1 or user2.
# 14  
Old 04-01-2013
Quote:
Originally Posted by MadeInGermany
HP-UX 11.23 find and SLED 11 find have a bug with + so \; is safer anyway.

\( -user user1 -o -user user2 \)
searches for user1 or user2.
That is unfortunate. HP-UX is a UNIX-branded system and correct operation of + is required for conformance. So someone should ask HP to fix this bug.

In a case like this, using + instead of \; can easily improve performance by a couple of orders of magnitude if hundreds of files are being processed.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

2. Shell Programming and Scripting

Using "Find" & Storing To Multiple Variables

Hello all! I'm pretty new to bash scripting, so this should be a pretty easy question to solve. For the last few hours, I've been creating a script that will list some of the following (based on a path I specify): # of directories # of files # of executable files files older than 365... (2 Replies)
Discussion started by: alphekka
2 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. AIX

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (2 Replies)
Discussion started by: thisissouvik
2 Replies

5. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

6. Shell Programming and Scripting

Find out if multiple files have lines ending with"r"

I am trying to find out which files in a group of files have lines ending in r. What I have is this: cat /tmp/*RECORDS| if grep r$>/dev/null; then echo "yes";else echo"no";fi Records is more than one file. There are the following files TEST-RECORDS /volume/testing /volume/programs ... (2 Replies)
Discussion started by: newbie2010
2 Replies

7. Shell Programming and Scripting

Using a single "find" cmd to search for multiple file types and output individual files

Hi All, I am new here but I have a scripting question that I can't seem to figure out with the "find" cmd. What I am trying to do is to only have to run a single find cmd parsing the directories and output the different file types to induvidual files and I have been running into problems.... (3 Replies)
Discussion started by: swaters
3 Replies

8. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

9. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

10. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies
Login or Register to Ask a Question