I'm answering these slightly out of order.
also the out csv file does not seem to list the file outputs 1 per line, more 1 single string of text, is there a way to put the file list findings 1 per line?
When you said a csv file - you didn't specify the format - so initially I went with a monolithic tab-delimited approach.
To do one file-name per line, you can just use skip using -printf and the format/field specifiers.
So my first example would become:
Code:
find /path/to/search/ -mtime -90 > /path/to/outputfile.csv
My second example would become:
Code:
find /path/to/search/ -newermt "2020-04-20 06:05:15" > /path/to/output.csv
final point, i seem to be getting these errors running your final option:
[root@RCRVNXCS0 nasadmin]# find /nas/quota/slot_2/root_vdm_2/isadhomes01/home/ph407/ -newermt "2020-04-20 15:00:00" -printf "%TY-%Tm-%Td@%TT\t%p\n" | find /nas/quota/slot_2/root_vdm_2/isadhomes01/home/ph407ot_vdm_2/isadhomes01/home/jltest/output.csv
find: invalid predicate `-newermt'
find: invalid predicate `-n'
Hmmm, well, what you've posted above isn't in any of my posts.
From what I can see there - you've attempted to chain the output of the first find to the input of a second find via a pipe...
Syntactically - what you've posted above is:
find {searchpath} -newermt {timestamp} -printf {format specifiers} | find /path/to/outputfile.csv
Which is NOT what I posted.
The syntax of the last command in my initial post was:
find {searchpath} -newermt {timestamp} -printf {format specifiers} > /path/to/outputfile.csv
And the last command in my previous post was:
find {searchpath} -newermt {timestamp} -printf {format specifiers} | sort -n > /path/to/outputfile.csv
Both are very different to what you posted.
Thanks for your assistnace, its much appreciated, could I pull in a csv list for source directories for this approach in any way?
Yes, you could do that.
This is one way:
Code:
while read searchpath; do
if [[ -d "$searchpath" ]]; then
find "$searchpath" -newermt "2020-04-20 15:00:00" >> /path/to/outputfile.csv
fi
done < /path/to/searchpaths.csv
That literally just reads the file /path/to/searchpaths.csv, line by line. Checks if each line is a valid path to a directory. If it is a valid path, it performs a find and appends the paths to anything it finds to /path/to/outputfile.csv.
That would be the simplest method.
If you wanted the output sorted by modification time, and to see the sorted output in blocks - with one block per find command - you could modify it like this:
Code:
while read searchpath; do
if [[ -d "$searchpath" ]]; then
echo "Found at $searchpath:" >> /path/to/outputfile.csv
find "$searchpath" -newermt "2020-04-20 15:00:00" -printf "%TY-%Tm-%Td@%TT\t%p\n" | sort -n >> /path/to/outputfile.csv
echo >> /path/to/outputfile.csv
fi
done < /path/to/searchpaths.csv
That will put all of the output into a single file, with each search separated into sorted blocks. Each line would contain a time-stamp and a path/filename.
Optionally, if you want all of the results in a single file and you don't care about which find operation they're from and you just want ALL of them to be sorted by timestamp - you could simply omit the lines used to separate the blocks of results and defer the sort until the last find has been performed - yielding a complete list of paths sorted by modification date, starting with the oldest and ending with the newest.
e.g. something like this:
Code:
while read searchpath; do
if [[ -d "$searchpath" ]]; then
find "$searchpath" -newermt "2020-04-20 15:00:00" -printf "%TY-%Tm-%Td@%TT\t%p\n" >> /path/to/outputfile.csv
fi
done < /path/to/searchpaths.csv
sort -n /path/to/outputfile.csv > /path/to/sortedoutputfile.csv
rm /path/to/outputfile.csv
Above writes the output from ALL of the find commands to a single file - then after all of the find commands are complete - we write the sorted output to a new file and remove the original output file.
Taking things further - you might not want to see the time-stamps in the final, sorted file. Perhaps you only wanted the time-stamps to perform the sort, but don't want them in the file.
In which case, the sort command at the end of the above script would become:
Code:
sort -n /path/to/outputfile.csv | awk '{print $2}' > /path/to/sortedoutputfile.csv
Or in the example where we're putting the results into sorted blocks, you could strip out the timestamps in the output file by modifying the piped part at the end of the line containing the find command to:
Code:
| sort -n | awk '{print $2}' >> /path/to/outputfile.csv
And that's just a few ideas, off the top of my head. The possibilities here are pretty much unlimited. It all depends on what you're looking for in the output file.