John
John

Reputation: 2141

tail and head command in Linux

While executing,

$ls -1rt /directory | head -n 3 file1.txt file2.txt file3.txt

$ls -1rt /directory | tail -n 3 file2.txt file3.txt

Could anyone tell me how the tail and head works internally during file listing and why this difference in no.of files?

Thanks in advance

Upvotes: 0

Views: 10130

Answers (1)

phaazon
phaazon

Reputation: 2002

head lists a certain amount of lines of your file. It won’t read it integraly, just the few first lines. tail does exactly the same thing, but starts at the end of the file. The -n 3 parameter is here to stop reading after 3 lines, then prints them only.

Upvotes: 1

Related Questions