LinuxQuestions.org
Help answer threads with 0 replies.
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 11-30-2011, 04:57 PM   #1
ifitz
LQ Newbie
 
Registered: Nov 2011
Posts: 1

Rep: Reputation: Disabled
Using the find command to list all files older than 2 years


I have a need to use the find command to go through our 2TB xraid, identify all files older than 720 days and list them in a text file. Any help would be greatly appreciated.

find -type f -mtime +720 -path /Volumes/XRAID/* "*.* -fprintf /textfile.txt
 
Old 11-30-2011, 05:08 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, and welcome to LQ!

Code:
find -type f -mtime +720 -path "/Volumes/XRAID/*" -fprintf /textfile.txt
You seem to have sensible invocation there ... what's the problem?


Cheers,
Tink

Last edited by Tinkster; 11-30-2011 at 05:09 PM.
 
Old 12-01-2011, 03:39 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
It usually helps when diagnosing a problem to detail exactly what the symptoms are. How about posting the output/error message you do get?

But anyway:

Code:
find -type f -path ...
The usual syntax is to give the top level directory(ies) to search from as the first argument(s), before any matching options. If you don't specify anything, then find defaults to searching pwd. So if you run the command from /, for example, it will search the whole system, which will most likely work, but will be searching a much larger space than necessary for your needs.

Second, -path is one of several options you can use to match specific file name patterns inside the given search space. Since you say you want to find all older files, you shouldn't need to use it, assuming you give it a reasonable starting path first.

But then there's this:
Code:
-path /Volumes/XRAID/* "*.*
The path given here is nonsensical. First of all, there's only a single quote-mark (which is a shell syntax error and should keep the command from executing), and some odd-looking, unprotected, globbing patterns.

Remember that the shell has it's own globbing feature that gets expanded before the command is run, so /Volumes/XRAID/* will expand to /Volumes/XRAID/file1 /Volumes/XRAID/file2 /Volumes/XRAID/file3, etc, before the command is run, and similarly *.* will expand to almost all files in the current directory. You have to be careful to quote any globbing or regex patterns to protect them from the shell and have them passed to find as-is.

Code:
-fprintf /textfile.txt
-printf/-fprintf are used when you want to define a specific output format for the results. But you haven't supplied the option with a format string to use. If you don't need the file names in the output to be structured in any particular way, just use -fprint. If you do need to use printf, check the manpage for the appropriate syntax and available formatting options.


So in all, I would suggest something more like this:
Code:
find /Volumes/XRAID -type f -mtime +720 -fprint /textfile.txt
This will search the /Volumes/XRAID directory tree for all normal files that are older than 720 days, and output the list to the text file.

Edit: Here are a couple of links about using find:
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html

Last edited by David the H.; 12-01-2011 at 03:46 PM. Reason: as stated
 
1 members found this post helpful.
  


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
Find directory older than x and mv directory with sub files command ajhart Linux - Newbie 4 07-15-2011 06:24 AM
find one day older files kirukan Linux - Newbie 3 05-31-2011 11:37 PM
[SOLVED] Delete regular files (not hidden files) with find + rm in one line older than 15 Virtuose Linux - Newbie 1 01-08-2011 06:24 PM
LXer: fdupes - Command line tool to find and list/delete duplicate files LXer Syndicated Linux News 0 10-28-2008 04:40 PM
find files older than another file bmeckle Linux - Software 2 10-21-2004 11:50 AM


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