The cat
command in Bash is used to concatenate and display the contents of files. It is a simple yet powerful tool that allows users to read file contents directly in the terminal or combine multiple files into one.
The basic syntax of the cat
command is as follows:
cat [options] [arguments]
-n
: Number all output lines.-b
: Number non-empty output lines.-E
: Display a dollar sign ($
) at the end of each line.-s
: Suppress repeated empty output lines.-A
: Show all characters, including non-printing characters.cat filename.txt
cat file1.txt file2.txt
cat file1.txt file2.txt > newfile.txt
cat file1.txt >> file2.txt
cat -n filename.txt
cat -s filename.txt
cat
in combination with other commands through piping to process file contents further.less
or more
instead of cat
to avoid overwhelming the terminal.>
) to avoid overwriting existing files unintentionally. Always double-check your command before executing it.