Search code examples
listcommandlimitcp

How to Copy some number of files from one directory to another with cp command?


I have 100 files in one folder. Their names are 1 to 100.

I want to copy files 1 to 50 into another folder named a. Something like this, which is not nice work:

cp 1 2 ... 50 ./a

Solution

  • cp `find . -maxdepth 1 -type f | sort | head -50` a

    cp `find . -maxdepth 1 -type f | sort | tail -50` b