Linux commands

Page: ()   1  2  3  4  5  6  ()

Command:

cat
show contents of file

http://www.opengroup.org/onlinepubs/9699919799/utilities/cat.html





Description of commmand / detailed explanation:

The cat command lets you view text files. If you're familiar with MS-DOS, the cat command is similar to the DOS type command.

However, the cat command gets its name from the word concatenate, and as that name implies, the cat command can let you merge several files together, as you'll see in the examples below.

In its most basic use, the cat command lets you display the contents of a text file to standard output, more commonly known as your screen.

The Cat command is often used in bash scripts to add or remove other data to the file in question. The Tac command (Cat backwards) prints everything the other way round, from bottom to top, instead of from top to bottom.
Command options:
cat filename The name of the file or files that you wish to look at or perform tasks on.
cat -n Precede each line output with its line number.
cat -b Number the lines, as -n, but omit the line numbers from blank lines.
cat -u The output is not buffered. (The default is buffered output.)
cat -s cat is silent about non-existent files.
cat -v Non-printing characters (with the exception of tabs, new-lines and form-feeds) are printed visibly. ASCII control characters (octal 000 - 037) are printed as ^n, where n is the corresponding ASCII character in the range octal 100 - 137 (@, A, B, C, . . ., X, Y, Z, [, \, ], ^, and _); the DEL character (octal 0177) is printed ^?. Other non-printable characters are printed as M-x, where x is the ASCII character specified by the low order seven bits.
cat -e A $ character will be printed at the end of each line (prior to the new-line).
cat -t Tabs will be printed as ^I's and formfeeds to be printed as ^L's.

*If the -v is used -e and -t will be ignored.




How to use it: cat [-u] [file...]



Typical Usage Examples:

cat file1.txt file2.txt > file3.txt - Reads file1.txt and file2.txt and combines those files to make file3.txt.

cat file1 file2 file3 > file4 - Creates a file from concatenating file1, file2, and file3.

cat -n myfile.txt - Show line numbers on the right hand side on each line

cat -T myfile.txt
- The T option shows TAB characters.

cat -v myfile.txt
- The -v option shows all non-printing characters, except for line feed and tab

cat -Tv myfile.txt - You can combine the 2 options too


Useless use of cat

UUOC (from comp.unix.shell on Usenet) stands for “Useless Use of cat”. As received wisdom on comp.unix.shell observes, “The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.” Nevertheless one sees people doing

cat file | some_command and its args ..... 

instead of the equivalent and cheaper

<file some_command and its args ... 

or (equivalently and more classically)

some_command and its args ... <file 



Available in:

debian
fedora
gentoo
suse
mandriva
ubuntu
Related commands:

  • ed
  • pico
  • tac
  • tee
  • touch

Page: ()   1  2  3  4  5  6  ()