05-C.6: Working with Files and Directories - cat Command

Linux - The Penguin Marches On · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    05-C.6: Working with Files and Directories - cat Command

    EXAM OBJECTIVES COVERED
    2.3 Given a scenario, create, modify, and redirect files.
    3.1 Given a scenario, apply or acquire the appropriate user and/or group permissions and ownership.

    Linux File and Directory Commands

    It is easy to get overwhelmed by the sheer number of Linux commands. Depending on which list you look at you will find anywhere from about 125 to over 600 (the 600 number includes a lot of commands from various distributions).

    This portion will cover some of the commands that will be useful for managing files and directories.

    The cat Command

    The cat (short for concatenate) command is a fairly simple tool designed to concatenate and write file(s) to your screen, which is known as standard output (stdout). The simplest use of cat is to show the contents of a file. One of the most common ways to use the cat command is for viewing configuration files, such as those in the /etc directory. The cat command will display a file without risking damage to it. Opening a critical configuration file using an editor such as Vi or Nano could inadvertently make unwanted changes to the file. The cat command is not an editor and therefore poses no risk of making changes to a file's content.

    Syntax:

    cat [filename]
    

    Command Options:

    Option Option Meaning
    -A Equivalent to -vET.
    -b Number nonempty output lines.
    -e Equivalent to -vE.
    -E Display $ at end of each line.
    -n Number all output lines.
    -s Suppress repeated empty output lines.
    -t Equivalent to -vT.
    -T Display TAB characters as ^I.
    pbmac@ubuntu $ cat temp
    Not like the brazen giant of Greek fame,
    With conquering limbs astride from land to land;
    Here at our sea-washed, sunset gates shall stand
    A mighty woman with a torch, whose flame
    pbmac@ubuntu $

     In the example the cat command is used to display the contents of the file temp.


    05-C.6: Working with Files and Directories - cat Command is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by LibreTexts.