How do I copy top X files from a directory to another using terminal command?

I have a directory more than 1200+ files. How do I copy the top 1000 lines of that directory to another directory?


Solution 1:

find . -maxdepth 1 -type f | head -1000 | xargs cp -t foo_dir where foo_dir is the destination where the files will be copied.

find . -maxdepth 1 -type f will look for files, on the current directory only. The output of that will be pipped to the command head that will return the top 1000 results. The result of that will be pipped to xargs that will use the cp command, one per line of results, to copy the files to a destination directory of your choice.