How to find from / but exclude certain folder?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to find from / but exclude certain folder?
# 1  
Old 06-15-2012
How to find from / but exclude certain folder?

SmilieHi Unix Specialists,

I need your advice on how to find all the files from root ( / ) filesystem but exclude those from /export/home (different filesystem) folder. Below are some of the find statements that I have tried without success:

Code:
find / -name '/export/home' -prune -o print -ls

Code:
  find / -type d -name '/export/home' -prune -o -ls
  find / -type d -name "\/export\/home" -prune -o -ls 

General searches & man page suggest similar commands but still couldn't work it out still.

I am running on Solaris 10 x86 platform.

Your assistance would be much appreciated.

Thanks,

George
# 2  
Old 06-15-2012
I dont get you here, what are you looking for?
If /export/home is a separate filesystem, why are you looking for it then?
# 3  
Old 06-16-2012
Hi vbe,

I need to search for all the files from / onwards which means that it would also pickup everything on /export /home as well. As a result, I am looking for the right find syntax command to list every single files & folders starting from / (root) filesystem but ignore or bypass /export/home folder which is also a filesystem.

One way to do this is to unmount /export/home before running "find / -ls". However, it is not possible to unmount this filesystem due to opened files & database in a production environment.

Thanks,

George
# 4  
Old 06-16-2012
Do not use -name, use -path (I hope it works in Solaris):

Code:
find / -type d -path /export/home -prune -o -ls

# 5  
Old 06-16-2012
A workaround for find without -path:
Code:
find / -type d -name home -exec test {} = /export/home \; -prune -o -ls

The -name home expression is not required, but it saves work by preventing -exec test ... when it cannot possibly succeed.

Regards,
Alister

Last edited by alister; 06-16-2012 at 06:28 PM..
# 6  
Old 06-16-2012
Another way. Work from the mounted filesystem list and ignore /export/home .
Code:
#!/bin/ksh
mount | awk '{print $1}' |grep -v "\/export\/home" | sort | while read filesystem
do
     find ${filesystem} -xdev -type f -print
done

The "-type f" is because you mentioned files not directories.
The "sort" is because I like things on order !
The "-xdev" confines the "find" to that filesystem, thus avoiding duplicates caused by links.



Ps. If you actually wanted to only search the root filesystem, the "-xdev" is a big hint.

Last edited by methyl; 06-16-2012 at 07:42 PM.. Reason: mispaste
# 7  
Old 06-18-2012
Bug How to find from / but exclude certain folder?

Hi All,

Thanks to all 3 respondent to my queries. Below are the out the outcome from your suggestions:

Quote:
Len wrote:
find / -type d -path /export/home -prune -o -ls
find: bad option -path
find: [-H | -L] path-list predicate-list (Solaris does not support -path syntax)


Quote:
alister wrote:
find / -type d -name home -exec test {} = /export/home \; -prune -o -ls
Brief to the point and works fine and make use of all the functionalities available in find.

Quote:
methyl wrote:
#!/bin/ksh
mount | awk '{print $1}' |grep -v "\/export\/home" | sort | while read filesystem
do
find ${filesystem} -xdev -type f -print
done
Too much scripting which doesn't make use of all the built-in features in find even though it also worked.

The second suggestion is most useful even though it is much appreciated for all your inputs.

Thanks,

George
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and exclude what is in file

Hello everyone, I try to find folders older than 3 years and display them, but excluding some directories, the below code does NOT exclude listed directories: find . -maxdepth 3 -mtime +1095 -type d -exec ls -l {} \; | grep -vFf oldExclude >> older oldExclude Folder1/ Folder2/... (7 Replies)
Discussion started by: Abu Rayane
7 Replies

2. Shell Programming and Scripting

How-To Exclude Directory in find command

How can i tweak the below find command to exclude directory/s -> "/tmp/logs" find . -type f \( ! -name "*.log*" ! -name "*.jar*" \) -printNote: -path option/argument does not work with the version of find that i have. bash-3.2$ uname -a SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v (7 Replies)
Discussion started by: mohtashims
7 Replies

3. Ubuntu

[Solved] Using Find with an exclude/exclude file

I am familiar with using tar and exclude/include files: tar zcf backup.dirs.tgz --files-from=include.mydirs --exclude-from=exclude.mydirs --no-recursion but was wondering if I could use find in the same way. I know that you can just specify the directories to exclude but my list is... (2 Replies)
Discussion started by: metallica1973
2 Replies

4. Shell Programming and Scripting

Find command with exclude

I had a Shell script that removes the files that are in a directory older than the specified days. find /test/files -mtime +10 I would like to add another condition to the find command above that is to exclude any file starting with ‘CGU' Thanks (1 Reply)
Discussion started by: db2dbac
1 Replies

5. Shell Programming and Scripting

Find folder within folder, then find other folder in same dir

Hi all I'm new to your forum but not new to shells. I'm having a little trouble though as it's been quite some time since I scripted. Here's what I'm trying to do: I'm trying to search a directory named '/var/root/Applications' for another directory 'fooBar'. The "Applications" directory... (9 Replies)
Discussion started by: DC Slick
9 Replies

6. Shell Programming and Scripting

Exclude a directory in 'find'

Hi, I'm in the process of writing a shell script which will be ran under cron hourly and will check for files of specific age in my ftp folder, then moves those over inside a folder called "old" (which is within the ftp dir). But, I'm unable to figure out how to exclude the "old" folder when... (1 Reply)
Discussion started by: mutex1
1 Replies

7. Shell Programming and Scripting

Help - Find command to exclude sub-directories

Hi Forum. I'm trying to write a script that finds and deletes files that are older than 300 days. The script will read a table that contains the following 3 columns: 1st col: “Y” means sub-directory scan; "N" means no subdirectory scan 2nd col: sub-directory location 3rd col: File prefix... (7 Replies)
Discussion started by: pchang
7 Replies

8. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

9. Shell Programming and Scripting

Find but exclude directories

Hello, I have a line in my script to find the files changed in the last 24 hours. It is as below: find /home/hary -type f -mtime -1 I now want to exclude a directory named "/home/hary/temp/cache" from the above find command. How do I add it to my script? Any help is appreciated. ... (9 Replies)
Discussion started by: tadi18
9 Replies

10. Shell Programming and Scripting

how do i exclude the current directory when using find?

i want to compile a list of files in all sub directories but exclude the current directory. the closest i could get was to search 'only' the current directory, which is the opposite of what i wanted. find . ! -name . -prune (7 Replies)
Discussion started by: mjays
7 Replies
Login or Register to Ask a Question