Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving large number of files [duplicate]

Tags:

bash

If I run the command mv folder2/*.* folder, I get "argument list too long" error.

I find some example of ls and rm, dealing with this error, using find folder2 -name "*.*". But I have trouble applying them to mv.

like image 582
DrXCheng Avatar asked Aug 13 '12 21:08

DrXCheng


People also ask

What is the fastest way to copy large amounts of data?

Solid-state drives (SSDs) are faster than older HDDs, so you can get an SSD for your machine for faster copying. The same applies when copying from or to an external drive. If you use a flash drive with USB 2.0 or an older external HDD, the transfer speeds will drag.

Is it faster to move or copy files to another drive?

If we are cutting(moving) within a same disk, then it will be faster than copying because only the file path is modified, actual data is on the disk. If the data is copied from one disk to another, it will be relatively faster than cutting because it is doing only COPY operation.

How do you copy and move multiple files?

Step 1: Click on the first file to be selected. Step 2: Hold down Ctrl and click on all the files that you want to select additionally. Step 2: Press the Shift key and click on the last file. Step 3: You have now selected all files at once and can copy and move them.


2 Answers

find folder2 -name '*.*' -exec mv {} folder \; 

-exec runs any command, {} inserts the filename found, \; marks the end of the exec command.

like image 197
Karl Bielefeldt Avatar answered Sep 21 '22 09:09

Karl Bielefeldt


The other find answers work, but are horribly slow for a large number of files, since they execute one command for each file. A much more efficient approach is either to use + at the end of find, or use xargs:

# Using find ... -exec + find folder2 -name '*.*' -exec mv --target-directory=folder '{}' +  # Using xargs find folder2 -name '*.*' | xargs mv --target-directory=folder 
like image 28
Idelic Avatar answered Sep 22 '22 09:09

Idelic