Find all files for a user, excluding a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find all files for a user, excluding a directory
# 1  
Old 08-30-2010
Find all files for a user, excluding a directory

I have been searching, and cannot find an answer for this. I am trying to find all files for a user, lets call him (test001), and I want to exclude a specific directory.
Here is the command I run, it finds all files:
find / -user test001
I get this result:
> find / -user test001
/QSYS.LIB/QUSRSYS.LIB/TEST001.MSGQ (I would like to eliminate these)
/QSYS.LIB/QUSRSYS.LIB/TEST06.MSGQ (I would like to eliminate these)
/SNEGRON/CBNACWP.TXT
/SNEGRON/special990.txt
/SNEGRON/pgm1.txt
/test06
$
This works ok, except, that I want to exclude the /QSYS.IBM directory.

On the AS400, there is a command called WRKOBJOWN. The work with objects by owner command. It shows the following files owned by user test001. I'm sure someone will say, why not just use this command. Well, in the case of a user that owns thousdands of objects, its not easy to use this command because to many objects are listed and there are screens and screens full of objects.


User profile . . . . . . . : TEST001

Type options, press Enter.
2=Edit authority 4=Delete 5=Display authority 7=Rename
8=Display description 9=Change owner

ASP
Opt Object Library Type Attribute Device
/SNEGRON/CBNACWP.T > *STMF *SYSBAS
/SNEGRON/pgm1.txt *STMF *SYSBAS
/SNEGRON/special99 > *STMF *SYSBAS
/test06 *DIR *SYSBAS
TEST001 QUSRSYS *MSGQ *SYSBAS
TEST06 QUSRSYS *MSGQ *SYSBAS

Ok, so this list shows 4 IFS file system objects and 2 OS400 objects that are owned by user test001.

I searched and found the prune command. I pieced together this command, but it doesn't work right.
Here is result with prune.
find . -user test001 -path QSYS.LIB -prune -o -type f
./classes/properties/systemlaunch.properties
./classes/wsa400.jar
./CBNACWP.TXT

Here is another example:
> find . -user test001 \( -name proc -type d \) -prune -o -exec ls -l '{}' \;
total: 1.032 megabytes
-rwxrwxrwx 1 SNEGRON 0 953910 Dec 2 2009 CBNACWP.TXT
drwxr-sr-x 3 QSYS 0 8192 Jan 13 2010 classes
total: 8 kilobytes
drwxrwsrwx 2 SNEGRON 0 8192 Aug 29 2008 RSE
total: 2.940 megabytes
drwxr-sr-x 2 QSYS 0 8192 Jan 13 2010 properties
-rwxr-xr-x 1 QSYS 0 658801 Feb 4 2008 wsa400.jar
total: 8 kilobytes
-rw-rw-r-x 1 SNEGRON 0 2664 Feb 4 2008 systemlaunch.prop
erties
-rw-rw-r-x 1 SNEGRON 0 2664 Feb 4 2008 ./classes/propert


It gives me a totally different list of files. Can someone provide me with the proper command??
I know I'm close, but every example I have found produces different results. I know the first find command is good, except I don't want to search in QSYS.LIB directory. My search should be. Find all files for user test001, excluding the qsys.lib directory and all its subdirectories.


Thanks for your help.
# 2  
Old 08-30-2010
Code:
find / -user test001 -type f -o -type d -name QSYS.LIB -prune

# 3  
Old 08-30-2010
Close, but no cigar.
The command you provided gives the following results:

> find / -user test001 -type f -o -type d -name QSYS.LIB -prune
/QSYS.LIB
/SNEGRON/CBNACWP.TXT
/SNEGRON/special990.txt
/SNEGRON/pgm1.txt

This appears to be the files in QSYS.LIB and not the others.
Thanks for the quick response.

---------- Post updated at 02:00 PM ---------- Previous update was at 01:57 PM ----------

Oh, never mind. This is right. I guess because technically, all files are in QSYS.LIB, it includes the directory. The 3 files are actually in /SNEGRON, so that is correct. It didn't include the additional files, so this must be correct.

Thanks.

---------- Post updated at 02:05 PM ---------- Previous update was at 02:00 PM ----------

Well, I'm not so sure now. There are 6 objects owned by user test001. They are as follows:
/SNEGRON/CBNACWP.T >
/SNEGRON/pgm1.txt
/SNEGRON/special99 >
/test06
TEST001
TEST06

Your command should have picked up the /test directory but did not. I did get the 3 files, but not the directory. The 2 remaining files are definately in QSYS.LIB.
Why wouldn't the /test06 directory get picked up??
# 4  
Old 08-30-2010
Not really :P Find always includes directory that is "pruned" it just isn't going inside. If you want directories owned by that user as well, then use:
Code:
find / -user test001 -o -type d -name QSYS.LIB -prune

# 5  
Old 08-30-2010
This looks good. It still picks up the /QSYS.LIB, but it does get all 4 files owned by this user. Thats exactly what I need.

find / -user test001 -o -type d -name QSYS.LIB -prune /QSYS.LIB
/SNEGRON/CBNACWP.TXT
/SNEGRON/special990.txt
/SNEGRON/pgm1.txt
/test06

Thanks for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find file with extension and excluding directory

Hi, I have an inquiry on how do I use the find command in Solaris Unix to find some file ends with extension : txt, err in the root directory with modified date of 30days and this find command will also need to exclude b directory and its subdirectory. All the files from the above find criteria... (5 Replies)
Discussion started by: snowfrost88
5 Replies

2. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

3. Shell Programming and Scripting

Find/searching files in subdirectories excluding the fiels in Parent Directory

Hi All, requirement is to find and remove the files from sub directories but it should exclude the files from parent directory. At present i am using the below one but it finds and remove files from both parent and sub directories. find ${PATH} -type f \( -name securitas\* -o -name \*gz... (1 Reply)
Discussion started by: Naveenkk
1 Replies

4. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

5. Shell Programming and Scripting

Find command to search files in a directory excluding subdirectories

Hi Forum, I am using the below command to find files older than x days in a directory excluding subdirectories. From the previous forums I got to know that prune command helps us not to descend in subdirectories. Though I am using it here, not getting the desired result. cd $dir... (8 Replies)
Discussion started by: jhilmil
8 Replies

6. Shell Programming and Scripting

Find ordinary files in directory input by user

I need to make a shell script that accepts a directory input by the user. The program searches for the directory and finds if it exists or not. Then if it does exist, it outputs the number of files within that directory. Here's what I have so far. result= echo "Please input a directory:... (5 Replies)
Discussion started by: itech4814
5 Replies

7. UNIX for Dummies Questions & Answers

Need help in excluding a particular directory using Find commad

Hi, I have a directory structure as below /home/gad/Merl/a/a1.txt /home/gad/Merl/b/a1.txt /home/gad/Merl/c/a1.txt How can I find the file a1.txt but not from directory 'a' and it(the filw) should loaded 6 days ago.. Can any one pls help,quick reply much appriciated.. Thanks. (1 Reply)
Discussion started by: jagadish_gaddam
1 Replies

8. UNIX for Dummies Questions & Answers

Find Files in a Directory Excluding Subdirectories

Hi, I have a filename Location.txt in a directory /abc. Similar name file is present in its subdirectory /abc/xyz. I want to find the file which is present only in /abc and not in /abc/xyz. Please any1 of u can provide a quick suggestion. Its very urgent. Thanks, Amol (2 Replies)
Discussion started by: Amol_Dicholkar
2 Replies

9. UNIX for Advanced & Expert Users

find excluding a directory and a file

Hi I have some 5 folders and two files in the current directory. I want to delete all, expect one folder(files in the folder too should not be deleted) and a file in the current directory. Lets say the folder and file that should not be deleted as 'a'(folder name) and 'b'(file name). Can you... (1 Reply)
Discussion started by: ammu
1 Replies

10. UNIX for Dummies Questions & Answers

Find all files created by a specified user in a directory and its subdirectories

Is there a command or shell script which can be used for Finding all files created by a specified userid in a directory and its subdirectories. Say, I want to find all such files in directory /abc as well as in all the subdirectories such as /abc/xyz or /abc/xyz/pqr aqnd so on which was created... (5 Replies)
Discussion started by: abhilashnair
5 Replies
Login or Register to Ask a Question