Display and move file content with cat

Sometimes while working in our Linux machines, we need to grab some information as a reference from certain files. This is especially important to those who work in the Linux shell exclusively on a headless server or SSH. We have a pretty quick tool that can do just that: cat.

cat

Credit: Google Images

cat(located in /bin/) allows for grabbing the contents of a file and output it to stdout – an area of the Linux shell where text may be placed when a command is executed. This allows us to get a quick look of a file to use as a reference. It may also be used to take the output text from it and place it into another file.

For example, lets say the we have a file called pets.list containing the following:

Dog
Cat
Horse
Pony
Leopard
Lion

Now we’re going to do this:

sudo cat pets.list

Once the command has been executed, the contents of pets.list will be displayed below it. In some cases, a file may have too much content inside and will end up flooding your shell terminal. For when that happens, you can do this:

sudo clear

This will wipe out all text from the entire shell terminal.

Copy file content to another file

You can also take the content of one file, and place it into another. This can be useful later on for when you need to merge 2 files together. Our second file will be petsbig.list which has the following content inside:

Hippo
Dinosaur
Tiger

We are now going to dump the contents of petsbig.list into pets.list:

cat petsbig.list >> pets.list

>> tells the program to forward what is supposed to be output in the shell, and instead places it at the top of pets.list. Your pets.list should now look something like this:

Hippo
Dinosaur
Tiger
Dog
Cat
Horse
Pony
Leopard
Lion

Also do note that if you use > instead of >>, the target file will be completely overwritten with the contents of the origin file.