slackware-current/slackbook/html/file-commands-output.html
Patrick J Volkerding 5a12e7c134 Slackware 13.0
Wed Aug 26 10:00:38 CDT 2009
Slackware 13.0 x86_64 is released as stable!  Thanks to everyone who
helped make this release possible -- see the RELEASE_NOTES for the
credits.  The ISOs are off to the replicator.  This time it will be a
6 CD-ROM 32-bit set and a dual-sided 32-bit/64-bit x86/x86_64 DVD.
We're taking pre-orders now at store.slackware.com.  Please consider
picking up a copy to help support the project.  Once again, thanks to
the entire Slackware community for all the help testing and fixing
things and offering suggestions during this development cycle.
As always, have fun and enjoy!  -P.
2018-05-31 22:41:17 +02:00

147 lines
5.5 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<title>Simple Output: cat and echo</title>
<meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" />
<link rel="HOME" title="Slackware Linux Essentials" href="index.html" />
<link rel="UP" title="Handling Files and Directories" href="file-commands.html" />
<link rel="PREVIOUS" title="Pagers: more, less, and most"
href="file-commands-pagers.html" />
<link rel="NEXT" title="Creation: touch and mkdir" href="file-commands-creation.html" />
<link rel="STYLESHEET" type="text/css" href="docbook.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"
alink="#0000FF">
<div class="NAVHEADER">
<table summary="Header navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<th colspan="3" align="center">Slackware Linux Essentials</th>
</tr>
<tr>
<td width="10%" align="left" valign="bottom"><a href="file-commands-pagers.html"
accesskey="P">Prev</a></td>
<td width="80%" align="center" valign="bottom">Chapter 10 Handling Files and
Directories</td>
<td width="10%" align="right" valign="bottom"><a href="file-commands-creation.html"
accesskey="N">Next</a></td>
</tr>
</table>
<hr align="LEFT" width="100%" />
</div>
<div class="SECT1">
<h1 class="SECT1"><a id="FILE-COMMANDS-OUTPUT" name="FILE-COMMANDS-OUTPUT">10.3 Simple
Output: <tt class="COMMAND">cat</tt> and <tt class="COMMAND">echo</tt></a></h1>
<div class="SECT2">
<h2 class="SECT2"><a id="AEN3559" name="AEN3559">10.3.1 <tt
class="COMMAND">cat</tt></a></h2>
<p><tt class="COMMAND">cat</tt>(1) is short for &#8220;concatenate&#8221;. It was
originally designed to merge text files into one, but can be used for many other
purposes.</p>
<p>To merge two or more files into one, you simply list the files after the <tt
class="COMMAND">cat</tt> command and then redirect the new output to a file. <tt
class="COMMAND">cat</tt> works with standard input and standard output, so you have to
use the shell redirection characters. For example:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd
class="USERINPUT">cat file1 file2 file3 &gt; bigfile</kbd>
</pre>
</td>
</tr>
</table>
<p>This command takes the contents of <tt class="FILENAME">file1</tt>, <tt
class="FILENAME">file2</tt>, and <tt class="FILENAME">file3</tt> and merges it all
together. The new output is sent to standard out.</p>
<p>One can also use <tt class="COMMAND">cat</tt> to display files. Many people <tt
class="COMMAND">cat</tt> text files through the <tt class="COMMAND">more</tt> or <tt
class="COMMAND">less</tt> commands, like this:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">cat file1 | more</kbd>
</pre>
</td>
</tr>
</table>
<p>That will display the <tt class="FILENAME">file1</tt> file and pipe it through the <tt
class="COMMAND">more</tt> command so that you only get one screen at a time.</p>
<p>Another common use for <tt class="COMMAND">cat</tt> is copying files. You can copy any
file around with <tt class="COMMAND">cat</tt>, like this:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">cat /bin/bash &gt; ~/mybash</kbd>
</pre>
</td>
</tr>
</table>
<p>The <tt class="COMMAND">/bin/bash</tt> program is copied to your home directory and
named <tt class="FILENAME">mybash</tt>.</p>
<p><tt class="COMMAND">cat</tt> has many uses and the ones discussed here are just a few.
Since <tt class="COMMAND">cat</tt> makes extensive use of standard input and standard
output, it is ideal for use in shell scripts or part of other complex commands.</p>
</div>
<div class="SECT2">
<h2 class="SECT2"><a id="AEN3603" name="AEN3603">10.3.2 <tt
class="COMMAND">echo</tt></a></h2>
<p>The <tt class="COMMAND">echo</tt>(1) command displays the specified text on the
screen. You specify the string to display after the <tt class="COMMAND">echo</tt>
command. By default <tt class="COMMAND">echo</tt> will display the string and print a
newline character after it. You can pass the <var class="OPTION">-n</var> option to
suppress the printing of the newline. The <var class="OPTION">-e</var> option will cause
<tt class="COMMAND">echo</tt> to search for escape characters in the string and execute
them.</p>
</div>
</div>
<div class="NAVFOOTER">
<hr align="LEFT" width="100%" />
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="33%" align="left" valign="top"><a href="file-commands-pagers.html"
accesskey="P">Prev</a></td>
<td width="34%" align="center" valign="top"><a href="index.html"
accesskey="H">Home</a></td>
<td width="33%" align="right" valign="top"><a href="file-commands-creation.html"
accesskey="N">Next</a></td>
</tr>
<tr>
<td width="33%" align="left" valign="top">Pagers: <tt class="COMMAND">more</tt>, <tt
class="COMMAND">less</tt>, and <tt class="COMMAND">most</tt></td>
<td width="34%" align="center" valign="top"><a href="file-commands.html"
accesskey="U">Up</a></td>
<td width="33%" align="right" valign="top">Creation: <tt class="COMMAND">touch</tt> and
<tt class="COMMAND">mkdir</tt></td>
</tr>
</table>
</div>
</body>
</html>