Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Do you have a method to quickly remove the first line of a file in bash shell ? I mean using sed or stuff like that.

share|improve this question
up vote 12 down vote accepted

One-liners in reverse order of length, portable unless noted.

sed (needs GNU sed for -i):

sed -i 1d file

ed (needs e.g. bash for $'...' expansion and here string):

ed file <<< $'1d\nw\nq'


awk NR\>1 infile > outfile


tail -n +2 infile > outfile

read + cat:

(read x; cat > outfile) < infile

bash built-ins:

while IFS= read -r; do ((i++)) && printf %s\\n "$REPLY" >> outfile; done < infile
share|improve this answer
or ed file1 <<< $'1d\nw\nq' – glenn jackman May 16 '11 at 14:58
In my case, tail is 15 times slower than sed. tail needs 13.5s, sed needs 0.85s. My file has ~1M lines, ~100MB. MacBook Air 2013 with SSD. – Jona Christopher Sahnwaldt Feb 1 at 16:26
$ tail -n +2 <<< $'1\n2\n3'
share|improve this answer

Using dd

fll=$(( $(head -n 1 $fn | wc -c) + 1))
dd if="$fn" of="${fn}.out" bs=1M iflags=skip_bytes skip=$fll
echo "Files differ by $(( $(find $fn* -printf "%s - \n" ; echo "0") )) bytes. First line of $fn is $fll bytes."

Add any iflags= and oflags= you might need - with commas separating them.

share|improve this answer

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.