Displaying file contents with cat

Instead of using more to display files, you can use cat (as in "concatenate"), which displays files but does not pause so you can read the information. Instead, it displays the file or files—which whizzzz by onscreen—and leaves you looking at the last several lines of the file (Code Listing 1.8).

The cat command also lets you redirect one or more files, offering a function that some versions of more do not.

To display file contents with cat:

1.
cat newest.programs

To begin, type cat plus the file name.

The file contents will appear onscreen; however, if the file is longer than a single screen, the contents will whir by, and all you'll see is the bottom lines of the file—the 24 or so that fit on a single screen.

  • cat newer.programs newest.programs

    You can also list multiple files for cat, with each file being displayed in the order specified. In this example the contents of newer.programs will zip by, then the contents of newest.programs will zip by.

  • cat newer.programs newest.programs
     > all.programs.

    In this example, we've added a redirection symbol (>) plus a new file name. This tells UNIX to print out both files; however, instead of displaying the files onscreen, it redirects them to the file called all.programs. Aha! Here's where cat does something better than more. See Redirecting input and output in this chapter for more information about redirecting commands.

Code Listing 1.8. With cat, long files whir by, and all you'll see is the bottom of the file. You can also redirect cat output to a file, as shown at the end of the listing.
$ cat newest.programs
...
xtermdos
xvminitoppm
xwdtopnm
xxd
yacc
ybmtopbm
yes
yuvsplittoppm
yuvtoppm
zcmp
zdiff
zeisstopnm
zforce
zgrep
zip
zipcloak
zipgrep
zipinfo
zipnote
zipsplit
zless
zmore
znew
$ cat newer.programs newest.programs >
  all.programs
$

Tip

If you inadvertently use cat with a binary file, you might end up with a whole screen of garbage. On some systems, you might try stty sane to fix it—more on this in Fixing terminal settings with stty in Chapter 3.


Tip

You can also view file contents using the more command. See the previous section, Viewing file contents with more , for details.


Table 1.1. Common UNIX Directories and Their Contents
DirectoryContents
/binEssential programs and commands for use by all users
/etcSystem configuration files and global settings
/homeHome directories for users
/sbinPrograms and commands needed for system boot
/tmpTemporary files
/usr/binCommands and programs that are less central to basic UNIX system functionality than those in /bin but were installed with the system
/usr/localMost files and data that were developed or customized on the system
/usr/local/binLocally developed or installed programs
/usr/local/manManual (help) pages for local programs
/usr/share/manManual (help) pages
/varChangeable data, including system logs, temporary data from programs, and user mail storage

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.105.137