Bash Concatenate Files
cat prints a file's contents to the terminal and can join several files into one continuous stream, which is where its name — concatenate — comes from.
Printing a File with cat
The most common use of cat is simply dumping a file straight to your terminal. It reads the file from start to finish and writes every line to standard output, making it the fastest way to check what's inside a short file without opening an editor.
Print a single file
$ cat notes.txt
Meeting at 10am
Bring the laptop
Don't forget coffeeJoining Several Files Together
Give cat more than one filename and it prints them one after another, in the exact order you list them, with no separator inserted between them. This concatenation behavior is where the command's name comes from.
Print two files back to back
$ cat chapter1.txt chapter2.txt
Chapter 1: Getting Started
Bash is a command interpreter...
Chapter 2: Loops and Conditionals
A for loop repeats a block...Merging Files into a New One
Redirect cat's output with > to merge multiple files into a brand new file. Use >> instead if you want to append onto the end of an existing file rather than overwrite it.
Merge three log files into one
$ cat jan.log feb.log mar.log > q1.log
$ wc -l q1.log
842 q1.log- cat file — print the whole file to the screen
- cat file1 file2 — print both files, one after another
- cat file1 file2 > merged.txt — join files into a new file
- cat file1 >> existing.txt — append a file onto another
- cat -n file — print with line numbers