cat Linux Command Cheatsheet

cat command is used to create, read & concatenate files in Linux/ Unix machines.

1. Creating a file with content

Lets create a file with name file1.txt and put following three lines of content into it.

First you need to run the following command to create a file

cat >file1.txt

When you press enter after the above command, it waits for the file content input. You can give multi line input and once you are done you need to press CTRL + D to save and exit.

2. Displaying file contents

Following command shows the content of given file

cat file1.txt

3. Display content from multiple files

Following command shows content from file1.txt followed by content from file2.txt

cat file1.txt file2.txt

4. Display Line Numbers before every line

Following command prefixes line numbers before each line from content

cat -n file1.txt

Following is an example for that

$ cat -n file1.txt
     1	line-1
     2	line-2
     3	line-3
     4	line-4

More Options

-eShows $ at the end of the content
-tTo see tabs in file, this shows tabs with ^I
-sremoves repeated empty lines in content

┬ęCopyright 2020 OneCompiler | Privacy Policy | Terms & Conditions