Remove The First Line Of A File In Linux

This can be done using the tail command.

tail -n +2 file.txt > file.tmp && mv file.tmp file.txt

We use a temporary file here as the redirection (>) from tail happens before tail is invoked by the shell. If we just redirected straight into the file we would get an empty file.

The sed command can also be used.

sed -i '1d' file.txt

Or using a combination of cat and sed, which needs the same redirection as the tail command above.

cat file.txt | sed 1d > file.tmp && mv file.tmp file.txt

Add new comment

The content of this field is kept private and will not be shown publicly.