cat – concatenate files and print to the standard output
cat is a simple yet very useful Unix command. It takes a name of one or more text files, and then shows their contents to the standard output as one stream of data.
cat is used as the go-to text file viewer for most of small configuration or data files. If you know that the file is about 10-20 lines of code, cat would be the perfect tool to show its contents.
For larger files, more command or its improved version – less command – are recommended.
cat Unix command example
or
for two files, it looks like this:
Line number in cat output
If you use the -n command line option with cat, your output will contain line numbers:
It is important to remember that -n numbers out the lines of the output generated by cat, not shows the number for each line in the original files. When working with more than one file, it’s easy to see what I mean:
While a line is a line, even if it’s empty, you could in some rare cases be only interested in numbering the lines which contain some information, and ignore the empty lines altogether. That’s when a -b option comes handy:
ubuntu$ ls -ald /tmp/protected/
drwxr-xr– 2 root root 4096 Mar 25 09:36 /tmp/protected/
See Also
- Basic Unix Commands
- Unix Commands
- ls command
- Filesystem navigation commands
- more command
- less command
- pwd command
cat is a simple yet very useful Unix command. It takes a name of one or more text files, and then shows their contents to the standard output as one stream of data.
cat is used as the go-to text file viewer for most of small configuration or data files. If you know that the file is about 10-20 lines of code, cat would be the perfect tool to show its contents.
For larger files, more command or its improved version – less command – are recommended.
cat Unix command example
or
for two files, it looks like this:
Line number in cat output
If you use the -n command line option with cat, your output will contain line numbers:
It is important to remember that -n numbers out the lines of the output generated by cat, not shows the number for each line in the original files. When working with more than one file, it’s easy to see what I mean:
While a line is a line, even if it’s empty, you could in some rare cases be only interested in numbering the lines which contain some information, and ignore the empty lines altogether. That’s when a -b option comes handy:
ubuntu$ ls -ald /tmp/protected/ drwxr-xr– 2 root root 4096 Mar 25 09:36 /tmp/protected/
See Also
- Basic Unix Commands
- Unix Commands
- ls command
- Filesystem navigation commands
- more command
- less command
- pwd command