Wednesday, 27 May 2015

Helpful command-line tips for Linux users part 7: displaying files - cat

list of all commands
explanation of the convention:
[] : values in square brackets are optional

cat BASIC USAGE 
cat [OPTION] [FILE]...- concatenate FILE(s) and print on the standard outputs, with no FILE, or when FILE is -, read standard input.
interesting options:
  -A     use ^ and M- notation, except for LFD and TAB, display TAB characters as ^I
  -b     number nonblank output lines
  -E     display $ at end of each line
  -n     number all output lines
  -s     never more than one single blank line

Standard output in most cases is the monitor, and standard input is keyboard, so when using cat without any parameters, what will happen is that you will be displaying on your screen immediately (after pressing ENTER) whatever you type.
This is sometimes useful for scripting purposes.

cat is not a very nice command when it comes to memory usage, so when you cat a large file carelessly, press Ctrl+S to stop displaying immediately. Then press Ctrl+C to stop the cat process.

Normal use of cat will be most often something like this:
> cat /etc/hosts
which will display the contents of the hosts file (if you have sufficient rights to see that file of course).

But mostly you will use cat with other commands such as this:
Split Files into 1024 Megabyte chunks, and then merge parts back into single file (with cat)
> split -b 1024m filename
> cat xa* > filename
Real Time Web Analytics