Concatenate and write files with cat command

cat copies each file (‘-‘ means standard input), or standard input if none are given, to standard output. Synopsis:

cat [option] [file]…

If you simply use cat then it will echo whatever you type on terminal. To exit this you can use Ctrl +D(EOF character) or Ctrl + C(interrupt the process).

If one or more arguments(filenames) are passed then it will show the contents of these filenames on terminal or standard output which can be redirected to a file using > filename. Given below are some important options related with cat command.

-v or --show-nonprinting displays control characters except for LFD(line feed or enter key) and TAB using ‘^’ notation and precede characters that have the high bit set with ‘M-’.

-E or --show-ends displays a ‘$’ after the end of each line.

-T or --show-tabs displays TAB characters as ‘^I’.

-A or --show-all is equivalent to -vET.

-b or --number-nonblank numbers all nonempty output lines, starting with 1.

-n or --number numbers all output lines, starting with 1. This option is ignored if -b is in effect.

With this we have discussed most important options of cat command. For a full reference please see coreutils documentation for your operating system.

Leave a comment

Your email address will not be published. Required fields are marked *