Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Arg list too long - trying to move some files to a sub directory

Options
  • 06-03-2014 5:10pm
    #1
    Registered Users Posts: 1,735 ✭✭✭


    Have a directory with over 100,000 files in it. I've created a sub directory called archive_2013 and want to put last years data into it. The files have the extension .bkp

    I've tried to use the following command ( 70 days is close enough to start of year)

    find *.bkp -mtime +70 -type f -print | xargs -i{} mv {} /archive_2013

    I keep getting "Arg list too long" , any ideas ?

    I've also tried

    find *.bkp -mtime +70 -type f -print -exec mv "{}" /archive_2013 \;

    but same error.

    Thanks.


Comments

  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    find ./ -name \*.bkp -mtime +70 -type f -exec mv {} /archive_2013\;
    

    You were asking the shell to expand *.bkp as an arg list for the find command


  • Registered Users Posts: 1,735 ✭✭✭ShatterProof


    Thanks but

    find ./ -name \*.bkp -mtime +70 -type f -exec mv {} /archive_2013\;

    is giving the error "find: incomplete statement" (meant to say this is AIX not sure if it makes a difference)


  • Registered Users Posts: 4,972 ✭✭✭opus


    Is this any use?
    find . -maxdepth 1 -type f -name "*.bkp" -exec mv {} /archive_2013 \;
    

    Don't have a directory with millions of files to test it.


  • Registered Users Posts: 6,210 ✭✭✭bonzodog2


    You could move all of them, and move the newer ones back (a smaller list).


  • Registered Users Posts: 2,720 ✭✭✭niallb


    find *.bkp -mtime +70 -type f -print -exec mv "{}" /archive_2013 \;

    Put single quotes around the name expression and careful with slashes and backslashes. Use -print0 in case there are spaces or weird things in the names.

    find . -name '*.bkp' -mtime +70 -type f -print0 | xargs mv "{}" archive_2013 \;

    AIX can be odd with expansion, and I think I remember single quotes being the magic bullet in a similar situation. Try that and see if you get a different error at least!

    Alternatively, find a smaller subset of files and try for
    mv *201001*.bkp archive_2013
    mv *201202*.bkup archive_2013
    and so on, but better to find the right command!


  • Advertisement
Advertisement