IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Sorting and moving files
I've got big pile o' files that are input for an analysis program and for reasons too complex to go into here I need to separate them out into directories, one per month.

Now, I can't find a sensible way of making find(1) do this; if I'm reading the manual right, there's no way of saying "find all files whose atime is in August 2003" without doing all sorts of horrible mojo regarding working out many seconds ago were the first and last days of August.

This leads me two a forktrident in the road.

On the one hand, I could use Perl and File::Find to get a file, look up its month with stat() and move it to the appropriate directory that way.

On the other hand, I could use Perl to list all the files long-stylee, and then process them on the basis of a regexp match.

On the gripping hand, I could brew some unpleasant shell to do this.

On the tentacle, I can't find a pre-canned solution to this but that doesn't mean there isn't one; searching anything for "sorting files" predictably drowns me in references to bogosort(1) and sort(1) and things related.


Peter
[link|http://www.debian.org|Shill For Hire]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Blog]
New Re: Sorting and moving files
How 'bout
\nls -lR --time-style=full-iso\n


and grep for "2003-08-"? Of course you might have a file called 2003-08- ...
-drl
New find -mtime

You need to know days between today and start/end of month in question. Or you can create files with specified start/end dates.

\r\n\r\n
\r\n
\r\nfind path -mtime +30 -mtime -60 -print0\r\n
\r\n
\r\n\r\n

...gets all files modified between 30 and 60 days ago, and prints them null-delimited (use with xargs 0).

\r\n\r\n
\r\n
\r\ntouch -d 'June 1, 2003' start\r\nfind path -newer start\r\n
\r\n
\r\n\r\n

...moves all files newer than 'start'. Start moving files from most recent month first with this method.

\r\n\r\n

If you need to do integer maths on shell, you can use the $(()) construct:

\r\n\r\n
\r\n
\r\nfind path -amin $(( 60 * 24 * 30 ))\r\n
\r\n
\r\n\r\n

...finds files modified within the past 30 days (60 minutes/hr * 24 hr/dy * 30 dy)

\r\n\r\n

If you need arbitrary precision, use bc: echo 'scale=3; (13/92)*100' | bc

--\r\n
Karsten M. Self [link|mailto:kmself@ix.netcom.com|kmself@ix.netcom.com]\r\n
[link|http://kmself.home.netcom.com/|http://kmself.home.netcom.com/]\r\n
What part of "gestalt" don't you understand?\r\n
[link|http://twiki.iwethey.org/twiki/bin/view/Main/|TWikIWETHEY] -- an experiment in collective intelligence. Stupidity. Whatever.\r\n
\r\n
   Keep software free.     Oppose the CBDTPA.     Kill S.2048 dead.\r\n[link|http://www.eff.org/alerts/20020322_eff_cbdtpa_alert.html|http://www.eff.org/alerts/20020322_eff_cbdtpa_alert.html]\r\n
New IAGAIWDWKS...TT
I Am Greg, And I Would Do What Karsten Says...This Time.

Seems what I would be doing. It sucks... but hey... oh-well... make lemonade.
--
[link|mailto:greg@gregfolkert.net|greg],
[link|http://www.iwethey.org/ed_curry|REMEMBER ED CURRY!] @ iwethey

[pungeant saying puckers here]
New are the files all over the disk?
DATE=`date +%b`
export DATE
cd /wherever
ls -LR | grep $DATE | | awk '{print $9}' | cpio -pd /dirTheyNeedToBeIn
thanx,
Bill
America, Love it or give it back
questions, help? [link|mailto:pappas@catholic.org|email pappas at catholic.org]
     Sorting and moving files - (pwhysall) - (4)
         Re: Sorting and moving files - (deSitter)
         find -mtime - (kmself) - (1)
             IAGAIWDWKS...TT - (folkert)
         are the files all over the disk? - (boxley)

Meta-Admin Notice: You Sillies
38 ms