Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
By top 1000 files you mean first 1000 files in alphabetical order? – binW Dec 30 '13 at 11:12
yes first 1000 files, no order needed for copy. – Muhammad Abdullah Dec 30 '13 at 11:13
up vote 5 down vote accepted

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.

share|improve this answer
Thanks alot ...! that's all what I need! – Muhammad Abdullah Dec 30 '13 at 11:23
cool glad it works. – Bruno Pereira Dec 30 '13 at 11:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.