Operating System - HP-UX
1758102 Members
2757 Online
108868 Solutions
New Discussion юеВ

finding filesystems with numeric UID

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

finding filesystems with numeric UID

Hi,
I would like to search file filesystems belonging to a user being which is only represented by its numeric UID. i.e. UID=200.

I've used the "find" utility to search for filesystems with UID=200:
#find / -user 200 -print

However, I would only like to get all directories with UID=200, which are just 1-level down the search once UID=200 is encountered.
e.g:
In the filesystem:
/home/cs/pg/users/ken_lee/MARS/tools/
if the directory MARS already have an instance of UID=200, then I would like to print it. This is regardless of the depth of filesystem tree.

Is there a way which I can specify the find utility to do so?

Or if a script is needed for such a task, could someone kindly show me how's its to be done?

Thanks
7 REPLIES 7
Robert-Jan Goossens
Honored Contributor

Re: finding filesystems with numeric UID

Hi,

# find . -type d -user 200 -print

Robert-Jan
Zeev Schultz
Honored Contributor

Re: finding filesystems with numeric UID

Hi
Need some clarification,in your example -
/home/cs/pg/users/ken_lee/MARS/tools is a mount point for filesystem?If so - MARS is not in this filesystem.What type of file are you
searching for (-type option of find)?If it's
a filesystem (and mounted) you can search with
find -type M (mounting point).For directories
use -type d.

Zeev.
So computers don't think yet. At least not chess computers. - Seymour Cray
Ian Dennison_1
Honored Contributor
Solution

Re: finding filesystems with numeric UID

Chern

Follow instructions above to find directories owned by UID 200. To trim the information down, do the following,...

find etc etc >/tmp/findrslt
export LNCOUNT=`cat /tmp/findrslt|wc -l'
cat /dev/null >/tmp/outrslt
while (( $LNCOUNT > 0 ))
do
export LINE1=`head -n 1 /tmp/findrslt'
grep "^$LINE1 /tmp/findrslt |head -n 2" >>/tmp/outrslt
grep -v "^$LINE1" /tmp/findrslt >/tmp/findrslt2
mv /tmp/findrslt2 /tmp/findrslt
export LNCOUNT=`cat /tmp/findrslt|wc -l'

done

Now you have the first 2 lines of every directory tree occurence of UID 200.

Share and Enjoy! Ian
Building a dumber user
Steve Steel
Honored Contributor

Re: finding filesystems with numeric UID

Hi


As shown just add the -d and get them all.

manually edit it afterwards.

There is no comfortable way with a script or find to do this.

You can play around with something like

oldir=lol
find / -user 200 -type d 2>/dev/null|
while read line
do
xx=$(echo $line|grep -v $oldir)
if [ "$xx" != "" ]
then
ll -d $line
oldir=$line
fi
done

Which will give you 1 layer down and then use these addresses to get the next one.

Regards

Steve Steel

Quote of the moment
-------------------
"We are drowning in information but starved for knowledge."
-- John Naisbitt
If you want truly to understand something, try to change it. (Kurt Lewin)
john korterman
Honored Contributor

Re: finding filesystems with numeric UID

Hi Chern,
please try the attached script.

regards,
John K.
it would be nice if you always got a second chance
Chern Jian Leaw
Regular Advisor

Re: finding filesystems with numeric UID

Zeev,
The mount point is /home/cs and I'm searching for files and directories having UID=200. However, for the case of directories, I'm only searching for the first instance of directories with UID=200. This is because all other directories beneath that directory having UID=200 also have the UIDs as 200.
Chern Jian Leaw
Regular Advisor

Re: finding filesystems with numeric UID

Steve,
What does the expression below found in your script mean?:
oldDir = |o|
I'm getting errors like:
./uid-2.sh[3]: o: not found.
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...]
./uid-2.sh[6]: xx: not found.

Could you help me out?

Thanks