Today we will learn basic linux command, which is very useful in daily use. Generally people used to forget these kind of commands.
- Given a list of text lines in a file, to display first 10 lines from the begining.
[user@localhost~]$ head foo.txt // Here foo.txt is a file name. If the file is not present in current directory, then you have to give absoute path of file. - To display last 10 lines.
[user@localhost~]$ tail foo.txt - Try -n option to specify number of lines to display
[user@localhost~]$ tail -n3 foo.txt // it will display last 3 lines
[user@localhost~]$ head -n4 foo.txt // it will display first 4 lines - And don't forget '+' in the tail and '-' in the head.
[user@localhost~]$ tail -n+10 foo.txt // start from the 10th line till last.
[user@localhost~]$ head -n-10 foo.txt // print all except the last 10 lines. - print from line 6 to 10
[user@localhost~]$ head -n10 foo.txt | tail -n5
0 comments :
Post a Comment