Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 06-03-2014 05:10PM
    #1
    Registered Users, Registered Users 2 Posts: 1,763 ✭✭✭


    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, Registered Users 2 Posts: 1,110 ✭✭✭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, Registered Users 2 Posts: 1,763 ✭✭✭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, Registered Users 2 Posts: 5,107 ✭✭✭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, Registered Users 2 Posts: 6,335 ✭✭✭bonzodog2


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


  • Registered Users, Registered Users 2 Posts: 2,780 ✭✭✭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