Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 over 1000 .csv files in a folder on Debian Squeeze. I am trying to create a new .csv file containing ONLY the first rows of each of these 1000 .csv files.

I tried:

read -r firstline < sourcefile_1.csv > headers.csv

But that only created a blank file. (And even if it did work, I would have copied only the first row of just one file.)

How do I write a command that copies the first rows of all 1000 files in the folder and add it to the new .csv file?

Thanks in advance!

share|improve this question
up vote 4 down vote accepted

head -q -n 1 *.csv > output.csv
-q supresses the headers that normally get printed, -n 1 prints only the first line

share|improve this answer
That worked! Fantastic! Thank you. – Spartanblogger Dec 4 '12 at 21:58

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.