2018-10-04 13:47:55 +00:00
|
|
|
---
|
|
|
|
title: Bash Cat
|
|
|
|
---
|
|
|
|
|
|
|
|
## Bash Cat
|
|
|
|
|
2018-11-05 07:01:23 +00:00
|
|
|
`cat` is one of the most frequently used commands in Unix operating systems.
|
2018-10-04 13:47:55 +00:00
|
|
|
|
2018-11-05 07:01:23 +00:00
|
|
|
`cat` is used to read a file sequentially and print it to the standard output.
|
2018-10-04 13:47:55 +00:00
|
|
|
The name is derived from its function to con**cat**enate files.
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
|
|
|
```bash
|
|
|
|
cat [options] [file_names]
|
|
|
|
```
|
|
|
|
|
|
|
|
Most used options:
|
|
|
|
|
2018-10-31 18:52:30 +00:00
|
|
|
* `-b`, number non-blank output lines
|
2018-10-04 13:47:55 +00:00
|
|
|
* `-n`, number all output lines
|
|
|
|
* `-s`, squeeze multiple adjacent blank lines
|
2018-11-01 05:37:13 +00:00
|
|
|
* `-v`, display non-printing characters, except for tabs and the end of line character
|
2018-10-04 13:47:55 +00:00
|
|
|
|
2018-10-11 23:00:38 +00:00
|
|
|
### Example
|
2018-10-04 13:47:55 +00:00
|
|
|
|
|
|
|
Print in terminal the content of file.txt:
|
|
|
|
```bash
|
|
|
|
cat file.txt
|
|
|
|
```
|
|
|
|
|
|
|
|
Concatenate the content of the two files and display the result in terminal:
|
|
|
|
```bash
|
|
|
|
cat file1.txt file2.txt
|
|
|
|
```
|
|
|
|
|
2018-11-05 07:01:23 +00:00
|
|
|
**Tip**: Using `cat` on a directory will cause error, so make sure it's a readable file.
|
|
|
|
|
2018-10-11 23:00:38 +00:00
|
|
|
#### More Information:
|
|
|
|
* Wikipedia: https://en.wikipedia.org/wiki/Cat_(Unix)
|
2018-11-05 07:01:23 +00:00
|
|
|
|
|
|
|
|