Copying a subset of files from a directory on CentOS

I had a huge number xml files (somewhere close to 100k files) and i needed to copy just a 1000 of them for a few tests on CentOS. I wasn’t interested in the order of the files, simply just any 1000 will do.

After trolling all over the internet, if found this simple solution.

 find $targetDir -maxdepth 1 -type f |head -1000|xargs cp -t $destDir

Where $targetDir was the path to the folder containing the large set of files, and $destDir is the folder in which i wanted to copy the 1000 files into.

Sweet and simple. Gleaned from here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s