castanyes blaves

Random ramblings about some random stuff, and things; but more stuff than things -- all in a mesmerizing and kaleidoscopic soapbox-like flow of words.

1/19/2005

 
head, tail and cat

[$] head file

prints first 10 lines

[$] tail file

prints last 10 lines

[$] head -n 4 file

prints first 4 lines

[$] tail -n 4 file

prints last 4 lines

[$] head -c 200 file

prints first 200 characters

[$] tail -c 200 file

prints last 200 characters

[$] head file1 file2 file3

will print the specified number of lines from each file separating them with the header beginning with ==> followed by the name of the file.

[$] cat file1 file2 file3 | head or [$] head -q file1 file2 file3

will print the specified number of lines from the input stream made up of the files listed after the cat command, but treated as one single file.

[$] tail -f /var/log/access.log

-f option tells tail to keep on reading data from the specified file and feeding it to its own standard output.

[$] cat file | head -c 1788 | tail -c 789

to read a chunk of 789 bytes starting from byte 1000 counted from the beginning of that file

[$] tac file (Note that tac is cat spelled backwards.)

to reverse the order of lines in a file


Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

Archives

200409   200412   200501   200502   200503   200504   200505   200506   200507   200508   200509   200510   200511   200512   200601   200602   200603   200604   200605   200606   200607   200608   200609   200610   200611   200612   200701   200702   200703   200704   200705   200707   200708   200709   200710   200711   200712   200801   200802   200803   200804   200805   200806   200807   200808   200809   200810   200811   200812   200901   200902   200903   200904   200905   200906   200907   200908   200909   200912   201001   201002   201003   201004   201007   201009   201011   201102  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]