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

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
–>
<web-app xmlns=”http://java.sun.com/xml/ns/javaee&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#8221;

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.                                                 –>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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