What is the 'cat' command for?

QuestionsQuestions8 SkillsProDec, 14 2025
0117

That's a very good question! You've successfully used echo and redirection to put text into a file. Now, how do we see what's inside that file?

The cat command, short for concatenate, is primarily used for:

  1. Displaying (Viewing) File Content: Its most common use is to print the content of one or more files directly to your terminal's standard output.

    • Example (after you've created file2.txt):
      cat file2.txt
      This command would show you:
      Hello, Linux
  2. Concatenating Files: As its name suggests, it can also combine the contents of multiple files into a single output or a new file.

    • Example: If you had file1.txt and file2.txt, you could do:
      cat file1.txt file2.txt
      This would display the content of file1.txt followed immediately by the content of file2.txt.
    • You can also redirect this combined output to a new file:
      cat file1.txt file2.txt > combined.txt
      This would create combined.txt containing the content of both files.
  3. Creating Small Files (less common nowadays): You can technically use cat to create a new file by redirecting its standard input (your keyboard) to a file. You type your content, press Enter, and then Ctrl+D to signal end-of-input.

    • Example:
      cat > newfile.txt
      # Type some text here
      # Press Ctrl+D when done
      This is less common than echo or text editors for creating content.

So, in the context of the current lab step, if you want to quickly check the content of file2.txt or .hiddenfile after creating them, cat is your go-to command!

Do you want to try using cat now with the files you've created?

0 Comments

no data
Be the first to share your comment!