LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-26-2010, 01:33 PM   #1
scr-be
LQ Newbie
 
Registered: Mar 2010
Location: So Cal
Distribution: RHEL, Debian, Ubuntu
Posts: 5

Rep: Reputation: 0
trouble with find


find . -atime +360 -exec ls -lah {} \;

that works fine, but i have a directory .snapshot that is a major waste of time to traverse through. i want find to exclude it. there is an option of -prune but i cannot seem to get it to work without saying
paths must precede expression

did some searching but cannot find example of -prune on the net

any ideas?

i was able to use ! -name .snapshot to avoid the directory, but this still does not address the issue of how to use -prune effectively.

Last edited by scr-be; 03-26-2010 at 04:21 PM. Reason: update
 
Old 03-26-2010, 05:41 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 164Reputation: 164
Prune is a odd function of sometimes annoying utility... try these to get an idea, be ultra careful using it with exec and -print as they DONT ACT THE SAME. Always test and test and test and test...

Code:
rweaver@core:~/test$ cat demo.sh
#!/bin/bash

echo "find . -print"
find . -print
echo

echo "find . -print \( -path ./.snapshot \) -prune"
find . -print \( -path ./.snapshot \) -prune
echo

echo "find . -print \( -path ./.snapshot \) -prune -exec echo \"exec on:{}\" \;"
find . -print \( -path ./.snapshot \) -prune -exec echo "exec on:{}" \;
echo

echo "find . -print \( -path ./.snapshot \) -prune -o -exec echo \"exec on:{}\" \;"
find . -print \( -path ./.snapshot \) -prune -o -exec echo "exec on:{}" \;
echo
rweaver@core:~/test$ ./demo.sh
find . -print
.
./file.png
./.snapshot
./.snapshot/demo2.fil
./.snapshot/demo.fil
./demo.sh
./file.1

find . -print \( -path ./.snapshot \) -prune
.
./file.png
./.snapshot
./demo.sh
./file.1

find . -print \( -path ./.snapshot \) -prune -exec echo "exec on:{}" \;
.
./file.png
./.snapshot
exec on:./.snapshot
./demo.sh
./file.1

find . -print \( -path ./.snapshot \) -prune -o -exec echo "exec on:{}" \;
.
exec on:.
./file.png
exec on:./file.png
./.snapshot
./demo.sh
exec on:./demo.sh
./file.1
exec on:./file.1
Those demos of it should give you a ~fairly~ good idea of what it expects and how it works... often times for simple exclusion its far easier to use ! whatever.
 
1 members found this post helpful.
Old 03-26-2010, 06:04 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by scr-be View Post
did some searching but cannot find example of -prune on the net

any ideas?
Tried to search on LQ site? Yep.
 
1 members found this post helpful.
Old 03-26-2010, 06:08 PM   #4
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
…-path ! '*.snapshot*'… ?

Last edited by Samotnik; 03-26-2010 at 06:09 PM.
 
Old 03-26-2010, 06:34 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
I believe the example in post #4 will still transverse the files in the .snapshot directory, even though the files in it will not be printed. Using prune, the directory will not be traversed, saving time if there are many files in the pruned directory. The find man page even says "To ignore a whole directory tree, use -prune..." in the paragraph describing -path.
 
1 members found this post helpful.
Old 03-26-2010, 06:56 PM   #6
hockeyman_102
Member
 
Registered: Apr 2006
Location: Washington
Distribution: Suse, CentOS, Ubuntu
Posts: 124

Rep: Reputation: 15
you could make it more of a bash script

Code:
#!/usr/bin/bash

find . -atime +360 | grep -v "snapshot" > find.no_snapshot.tmp

while read file; do
ls -alh $file
done < find.no_snapshot.tmp

rm find.no_snapshot.tmp
 
Old 03-29-2010, 12:11 PM   #7
scr-be
LQ Newbie
 
Registered: Mar 2010
Location: So Cal
Distribution: RHEL, Debian, Ubuntu
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by hockeyman_102 View Post
you could make it more of a bash script

Code:
#!/usr/bin/bash

find . -atime +360 | grep -v "snapshot" > find.no_snapshot.tmp

while read file; do
ls -alh $file
done < find.no_snapshot.tmp

rm find.no_snapshot.tmp

If .snapshot was not so large, it would not be a big deal and this script would apply. As read this script would only parse out .snapshot/* after find has traversed it. In the environment I work with .snapshot contains at least 4 exact copies of the data set where it exists. They are time delayed local archives. So to traverse .snapshot would cause for at least 4 times the amount of files required for the desired results.
 
Old 03-30-2010, 01:10 PM   #8
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 164Reputation: 164
Did my reply and examples tell you what you needed to know about how to use prune or do you need additional information?
 
Old 03-31-2010, 02:15 PM   #9
scr-be
LQ Newbie
 
Registered: Mar 2010
Location: So Cal
Distribution: RHEL, Debian, Ubuntu
Posts: 5

Original Poster
Rep: Reputation: 0
Thumbs up

Quote:
Originally Posted by rweaver View Post
Did my reply and examples tell you what you needed to know about how to use prune or do you need additional information?
Yes, it was quite informative. Was able to get the action I was looking for! Thanks!
 
  


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
Trouble getting .configure to find QT snowmobile74 Linux - Software 1 06-18-2009 08:51 PM
find trouble chandru.in Linux - Newbie 6 07-21-2005 08:10 AM
having trouble with ls and find finding files. dr_zayus69 Linux - Software 4 05-26-2005 11:36 AM
trouble with find command in bash vrdhananjay Linux - Newbie 3 10-31-2004 12:37 AM
Trouble Invoking JVM From C: Cannot Find libjava.so. eric.r.turner Programming 0 10-20-2003 11:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:05 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