How to display content of a file using head and tail commands Linux

Here is the solution if you want to display the first 20 lines of a file inside a Linux OS. use the following command

syntax –> head-linestobeshowed filename

linuxserver:/servers/apache-tomcat-6.0.18/conf # head -20 web.xml
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the “License”); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
See the License for the specific language governing permissions and
limitations under the License.
<web-app xmlns=”;

And, if you want to display the last 20 lines of a file inside a Linux OS.

syntax –> tail -linestobeshowed filename

linuxserver:/servers/apache-tomcat-6.0.18/conf # tail -20 web.xml

<!– ==================== Default Welcome File List ===================== –>
<!– When a request URI refers to a directory, the default servlet looks  –>
<!– for a “welcome file” within that directory and, if present,          –>
<!– to the corresponding resource URI for display.  If no welcome file   –>
<!– is present, the default servlet either serves a directory listing,   –>
<!– or returns a 404 status, depending on how it is configured.          –>
<!–                                                                      –>
<!– If you define welcome files in your own application’s web.xml        –>
<!– deployment descriptor, that list *replaces* the list configured      –>
<!– here, so be sure that you include any of the default values that     –>
<!– you wish to include.                                                 –>



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s