Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

up vote 4 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

 
discard

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.