Archive files by date - year

Discussion in 'General Linux' started by efromeroc, Mar 18, 2012.

  1. efromeroc

    efromeroc New Member

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Any suggestion about how can I move files by year to a specific folder. the chalenge is that the original folder has millions of files, so I cannot list the files.

  2. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    229
    Trophy Points:
    43
    Sure - this is probably a round-about way, but it should work.. touch two files for each year.. we'll use 2011.. compare files in the dir to those files.. move the ones that match..

    [xcode=shell]
    mkdir /path/to/2011
    touch --date "2011-01-01" /tmp/start
    touch --date "2012-01-01" /tmp/end
    for f in `find /path/to/millionfiles/ -type f -newer /tmp/start -not -newer /tmp/end`; do mv $f /path/to/2011/;done
    [/xcode]

    It may end up taking up all of the server resources.. so be ready to kill it :)
  3. DarthVader3257

    DarthVader3257 New Member

    Messages:
    45
    Likes Received:
    2
    Trophy Points:
    0
    I think that some coding will enable you to archive certain files by date and year. On Windows, it's obviously a lot easier due to the fact that you can simply select the way you would like for the files to be organized. Hope the issue had been solved, though.

Share This Page