LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-20-2010, 11:52 AM   #1
anu_1
LQ Newbie
 
Registered: Jan 2010
Posts: 12

Rep: Reputation: 0
Exclude NFS in find


Hi ,

I want to search files excluding the NFS ...

find / -mount -name 'filename' restricts the search only in the root disc partition,but the file can be in other partitions also...

Is there any way to exclude the NFS only...

Thanks for your help....
 
Old 01-20-2010, 11:55 AM   #2
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 488

Rep: Reputation: 78
you might be able to make use of find's '-fstype'
Code:
       -fstype type
              File  is  on  a  filesystem  of type type.  The valid filesystem
              types vary among different versions of Unix; an incomplete  list
              of filesystem types that are accepted on some version of Unix or
              another is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K.   You  can
              use  -printf  with  the  %F  directive  to see the types of your
              filesystems.
 
Old 01-20-2010, 12:31 PM   #3
anu_1
LQ Newbie
 
Registered: Jan 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Thank you so much ... :-)
 
Old 01-20-2010, 06:28 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Quote:
find / -mount -name 'filename' restricts the search only in the root disc partition
Actually, no. All filesystems are (logically) mounted under '/', and as find is recursive, that cmd would search ALL disk/partitions.
 
Old 01-20-2010, 06:49 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
I'm not at home now, but I think "-not -fstype nfs" would exclude files that are located on an nfs mount. The directory that the NFS filesystem is mounted on would be descended into, so it may be better to use the name of the directory it is mounted on in conjunction with -prune.

Suppose you had an nfs share mounted on $HOME/podcasts:
find $HOME -name $HOME/podcasts -prune -o -name "*.mp3" \;

This would search for MP3 files not in $HOME/podcasts and wouldn't even descend into $HOME/podcasts possibly saving considerable time.

You could also try:
find / -fstype d -prune -o <other search criteria> -print
for a more general solution where you don't know the names of the nfs mounts.

I can't test this now however. I'll leave that up to the OP.
 
Old 01-20-2010, 11:26 PM   #6
anu_1
LQ Newbie
 
Registered: Jan 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
I'm not at home now, but I think "-not -fstype nfs" would exclude files that are located on an nfs mount. The directory that the NFS filesystem is mounted on would be descended into, so it may be better to use the name of the directory it is mounted on in conjunction with -prune.

Suppose you had an nfs share mounted on $HOME/podcasts:
find $HOME -name $HOME/podcasts -prune -o -name "*.mp3" \;

This would search for MP3 files not in $HOME/podcasts and wouldn't even descend into $HOME/podcasts possibly saving considerable time.

You could also try:
find / -fstype d -prune -o <other search criteria> -print
for a more general solution where you don't know the names of the nfs mounts.

I can't test this now however. I'll leave that up to the OP.
..

Thanks so much....I am very new to Linux ..

find / -fstype nfs -type d -prune -o <other search criteria> -print
(you meant ..this ..right..?Sorry ..if ..I didn't understand properly..)

Thanks again...
 
Old 01-21-2010, 01:14 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
I mounted an nfs shared directory in my home directory.

The -fstype nfs test is successful for the files inside as well as the directory itself:
find . -maxdepth 1 -fstype nfs
./elite-downloads

This search used prune to skip the elite-downloads directory:
find . -fstype nfs -type d -prune -o -name "*.rar"

-print at the end is optional because it is the default action.

It will print the name of the elite-downloads directory, but won't descend into it and print files inside.

It took me some time to figure out using -prune. Don't feel bad if you don't get it from reading the man page.

Maybe you want the -xdev option with prevents descending directories on other filesystems.

---

I would recommend for things like backups, and searches to become familiar with which directories to work with and explicitly entering them instead of using the root directory (/).

You can have more than one directory, so a find command looking for new files could start with:
find /usr /home /boot /var
Some directories you don't want to backup. E.G. /tmp, /dev, /sys, /var/tmp, /proc

Descending /proc might cause problems as well. /proc & /sys are pseudo directories. The files aren't real, but created on the fly. One of these files is the entire memory space. You don't want to grep that!

Last edited by jschiwal; 01-21-2010 at 01:31 AM.
 
Old 01-21-2010, 01:52 AM   #8
anu_1
LQ Newbie
 
Registered: Jan 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
I mounted an nfs shared directory in my home directory.

The -fstype nfs test is successful for the files inside as well as the directory itself:
find . -maxdepth 1 -fstype nfs
./elite-downloads

This search used prune to skip the elite-downloads directory:
find . -fstype nfs -type d -prune -o -name "*.rar"

-print at the end is optional because it is the default action.

It will print the name of the elite-downloads directory, but won't descend into it and print files inside.

It took me some time to figure out using -prune. Don't feel bad if you don't get it from reading the man page.

Maybe you want the -xdev option with prevents descending directories on other filesystems.

---

I would recommend for things like backups, and searches to become familiar with which directories to work with and explicitly entering them instead of using the root directory (/).

You can have more than one directory, so a find command looking for new files could start with:
find /usr /home /boot /var
Some directories you don't want to backup. E.G. /tmp, /dev, /sys, /var/tmp, /proc

Descending /proc might cause problems as well. /proc & /sys are pseudo directories. The files aren't real, but created on the fly. One of these files is the entire memory space. You don't want to grep that!
Thank you so much for your help...
 
Old 10-17-2012, 02:21 PM   #9
mortalm
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Rep: Reputation: Disabled
Late to the party

Hey guys,

Just came across this after trying to do something similar and was unable to find a definitive way to exclude nfs mounts from my find searches. So I created this bulky monstrosity but it does the trick, this paticular one is just looking for files larger than 10MB:

Code:
NFSEXCLUDE=`mount | grep nfs | awk '{print $3}'` ; NFSEXCLUDE1=$(for mounts in `echo $NFSEXCLUDE`; do echo -n "-wholename $mounts -o "; done ) ; NFSEXCLUDE2=`echo $NFSEXCLUDE1 | sed 's/\(.*\).../\1/'` ; find / \( $NFSEXCLUDE2 \) -prune -o -size +10000k -print
Hope this helps,
~Mortalm
 
Old 10-17-2012, 02:40 PM   #10
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
Quote:
Originally Posted by mortalm View Post
was unable to find a definitive way to exclude nfs mounts from my find searches.
If you are going to post to an old thread, at least don't ignore what has been said earlier. Does the -fstype nfs -prune method not work for you? It looks like the nicest way of doing this.

Also,
Code:
`echo $variable`
# is equivalent to just
$variable
 
1 members found this post helpful.
Old 10-17-2012, 02:59 PM   #11
mortalm
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
If you are going to post to an old thread, at least don't ignore what has been said earlier. Does the -fstype nfs -prune method not work for you? It looks like the nicest way of doing this.
I apologize, I was not trying to disregard the above information, there are just some instances where using prune on the -fstype nfs has not been the correct method for me. But yes, it is definitely a simpler way of doing it.

Quote:
Also,
Code:
`echo $variable`
# is equivalent to just
$variable
Did the code posted work for you if you replace the
Code:
 `echo $variable`
with
Code:
 $variable
? As that was not the case on my end.

Was simply listing another method of doing it, even it is bulky.
 
Old 10-17-2012, 03:22 PM   #12
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
Quote:
Originally Posted by mortalm View Post
there are just some instances where using prune on the -fstype nfs has not been the correct method for me.
It would be quite useful to know when and why it doesn't work, please share.

Quote:
Did the code posted work for you if you replace the
Code:
 `echo $variable`
with
Code:
 $variable
? As that was not the case on my end.
I don't have any nfs mounts, and I don't really want to stress my disk with that find command, but the following code has the same output with `echo $NFSEXCLUDE` as $NFSEXCLUDE (tested with bash and dash):

Code:
NFSEXCLUDE=`mount | awk '{print $3}'` # removed grep
NFSEXCLUDE1=$(for mounts in $NFSEXCLUDE
    do echo -n "-wholename $mounts -o "
    done ) 
NFSEXCLUDE2=`echo $NFSEXCLUDE1 | sed 's/\(.*\).../\1/'` 
echo find / \( $NFSEXCLUDE2 \) -prune -o -size +10000k -print
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
nfs for syncing dirs, but want to exclude a dir Nielsrohrig Linux - Networking 3 07-29-2009 07:58 AM
exclude a dir via find in bash? agrestic Programming 3 01-30-2009 04:32 PM
exclude directories from find noir911 Linux - General 3 11-22-2006 07:39 AM
How can I exclude NFS with find with no visit david.dales Linux - General 2 08-24-2005 04:08 AM
exclude directory from find ebasi Linux - Software 8 07-17-2004 03:12 AM


All times are GMT -5. The time now is 10:45 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration