Skip to main content
Engineering LibreTexts

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

  • Page ID
    32144
  • 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.

    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 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.
    A Linux terminal showing the output of a cat command - the cat command simply displays the content of a file.
    Figure \(\PageIndex{1}\): Linux cat Command. ("cat command" by Patrick McClanahan is licensed under CC BY-SA 4.0)

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