Saturday, August 13, 2011

Linux Commands - cat,tac,head and tail

In this post, I want to show some file displaying commands that are very useful.

Cat

cat command is used to display the contents of a file in the terminal.

$ cat a.text 
Hi friends, I'm Ajay.
Here I'm posting about my MCA main project.

Tac

tac is same as cat, but shows the content of the file in reverse order.

$ tac a.text 
Here I'm posting about my MCA main project.
Hi friends, I'm Ajay.

Head

head is another file content display command, but having some advanced controls.

$ head a.text 

It will display first 10 lines of a file.

$ head -1 a.text 

It will display first line of the file.

Tail

The tail is opposite to the head command. 

$ tail a.text

It shows the last 10 lines of the file. If you want to see the last line of the file, type,

$ tail -1 a.text

So in our example file head and tail works as follows,

$ head -1 a.text 
Hi friends, I'm Ajay.

$ tail -1 a.text 
Here I'm posting about my MCA main project.

We can also save the output to another file using '>'

$ tail -1 a.text > b.text

Thanks

AJAY

No comments:

Post a Comment