Skip to content

What does that file contain? Ask cat!

December 19, 2009

This is going to be a short entry that deals with a very small command: cat. It’s basically used to manipulate the contents of a file in the shell. But do not under-estimate the power of cat by it’s seemingly small definition!

To print out the contents of a file try,
cat try
That’s it! Neat eh?

Of course, you can print out multiple files at the same time:
cat try1 try2 try3
and so on.

Of course you’ve to read and find out where does one file end and where does the next one begin. (If you know another way to do so, leave a comment in this entry.)

You can get numbered output i.e. each line will be numbered.
cat -n try

Here’s a way to copy a file using cat
cat try1 > try2
Just print all contents of try1 and redirect it to try2. Simple!

However, the coolest part should be writing to a file using cat. Here’s how it’s done.
cat > try
When you execute cat without the filename, the standard input is taken as input file and redirect the contents of standard input to try instead of standard output and voila! It’s working! To stop, just cancel it by keyboard interrupt – Ctrl+C.

Till next time, ciao!

Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: