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:
-
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):
This command would show you:cat file2.txtHello, Linux
- Example (after you've created
-
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.txtandfile2.txt, you could do:
This would display the content ofcat file1.txt file2.txtfile1.txtfollowed immediately by the content offile2.txt. - You can also redirect this combined output to a new file:
This would createcat file1.txt file2.txt > combined.txtcombined.txtcontaining the content of both files.
- Example: If you had
-
Creating Small Files (less common nowadays): You can technically use
catto 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:
This is less common thancat > newfile.txt # Type some text here # Press Ctrl+D when doneechoor text editors for creating content.
- Example:
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?