LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 08-12-2010, 05:09 PM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
sending find results to a file


I'm trying to do a

find /photos/* -type f -mtime +365

to find all my pictures that are over a year old, but i keep getting argument list too long. How can i view what all the results are, even if it just dumps it to a file that i have to open?
 
Old 08-12-2010, 05:37 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
find /photos/* -type f -mtime +365 > myphotos

will send the output of find to file myphotos.
 
Old 08-12-2010, 09:28 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by rjo98 View Post
I'm trying to do a

find /photos/* -type f -mtime +365

to find all my pictures that are over a year old, but i keep getting argument list too long. How can i view what all the results are, even if it just dumps it to a file that i have to open?
The problem is with the '*'. You not only don't need
it - it causes the problem because bash kindly expands
it for you. So find is (possibly?) fed a list of files
by bash, rather than iterating through a directory tree.

Imagine your "/photos" has 2000 jpgs and 500 subdirectories.

With the * what happens is that you're telling find to start
a search in 2500 locations. Hence the "argument list too long".



Cheers,
Tink
 
Old 08-13-2010, 06:50 AM   #4
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
thanks guys
 
Old 08-13-2010, 07:27 AM   #5
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Wink Just like this

Code:
find /photos/* -type f -mtime +365 | less
Enjoy.
 
1 members found this post helpful.
Old 08-13-2010, 07:31 AM   #6
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
oh, i like that too!!!
 
Old 08-13-2010, 01:37 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by Mr. Alex View Post
Code:
find /photos/* -type f -mtime +365 | less
Enjoy.
The "*" is still wrong.
 
Old 08-16-2010, 05:04 AM   #8
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Quote:
The "*" is still wrong.
Yes, I forgot, you don't need to type "*". The search is always recursive.
 
Old 08-16-2010, 05:31 AM   #9
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
I have to admit: I would prefer to pipe ls through grep over using find, like so:

Code:
ls /photos | grep "$KEYWORDS"
Of course, it doesn't work for anything other than text searching.
 
Old 08-16-2010, 05:41 AM   #10
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Smile locate

Or even simpler:
Code:
$ locate [keyword]
It's kind of quick search.

Last edited by Mr. Alex; 08-16-2010 at 05:42 AM.
 
Old 08-16-2010, 06:12 AM   #11
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
Quote:
Originally Posted by Mr. Alex View Post
Or even simpler:
Code:
$ locate [keyword]
It's kind of quick search.
Have to say it is much faster than ls | grep. I tries testing it with /usr (keyword "gnome" in Ubuntu) and - what do you know - it took just a few seconds to complete compared with up to a minute with ls | grep.
 
Old 08-16-2010, 11:32 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
FYI: locate is a db updated by the OS usually once a day (cron).
Doesn't exist on other *nixes afaik and may not always be up to date if your system has been shutdown for a while....

Last edited by chrism01; 08-17-2010 at 12:09 AM.
 
1 members found this post helpful.
Old 08-17-2010, 01:14 AM   #13
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by chrism01 View Post
FYI: locate is a db updated by the OS usually once a day (cron).
Doesn't exist on other *nixes afaik and may not always be up to date if your system has been shutdown for a while....
I have located on a few machines and I have never known it to automatically update tho it would be very easy to do. I prefer manually running updatedb because it then doesn't throttle the hard drive while the server maybe dealing with other things.
 
  


Reply



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
find -mtime gives unexpected results amchargue Linux - Newbie 3 08-12-2010 04:19 PM
Where do I find the results of unpacking a file with Gunzip? randyic Linux - Newbie 5 04-22-2009 08:36 PM
'find' gives different results when using -mtime with -print vs -exec BrianK Linux - General 1 12-08-2008 10:32 AM
Running find on / results in filesystem error Maeltor Linux - General 5 06-07-2006 11:20 AM
bash find results bendeco13 Linux - General 6 10-26-2004 11:48 AM

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

All times are GMT -5. The time now is 09:02 PM.

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
Open Source Consulting | Domain Registration