Find the answer to your Linux question:
Results 1 to 4 of 4
hi, i am running a simulation which outputs files with extension *.foo. a large number of such files (>50k) are generated, and i would like to move them from their ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Posts
    2

    RESOLVED: batch file move (>50k files) by file extension

    hi,

    i am running a simulation which outputs files with extension *.foo. a large number of such files (>50k) are generated, and i would like to move them from their current directory to another directory.

    i cannot use the usual scripts that make lists because i get the 'argument list too long' error. i think i need to use the 'find' command, with a test for the correct extension, and then a 'mv' command, but i am not familiar enough with the syntax to get it to work. i am going through the bash-scripting guide, but it seems a bit advanced for my purposes...i appreciate any suggestions.
    Last edited by pagliacci19; 02-18-2009 at 05:15 PM. Reason: RESOLVED

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Here's a find command that should work:

    Code:
    find /path/to/source -type f -maxdepth 1 -name "*.foo" -exec echo mv {} /path/to/dest/ \;
    This will just print what the mv commands will look like. There will be a mv command for every file moved. If it looks OK then remove the 'echo' and run again to actually move the files. Refer to the find manpage for details about the options used.

  3. #3
    Just Joined!
    Join Date
    Oct 2004
    Posts
    62
    Hi,
    the best solution is to zip all the 50000 files in one compressed file...

    Bye.

  4. #4
    Just Joined!
    Join Date
    Feb 2009
    Posts
    2

    RESOLVED: batch file move for >50k files -- move by extension type

    hi -- thanks for the suggestion.

    i tried this short while ago and wanted to make certain it worked before posting a reply -- yes, that command works fine.

    thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...