PDA

Click to See Complete Forum and Search --> : [RESOLVED] Quick terminal question


kregg
Jul 29th, 2007, 02:33 PM
What's the command to output whatever is in a file.

E.G. if there is a text file called hello.c. And if enter at the terminal:

kregg@vbf: ~ ???????? hello.c

It would come up, as an example, the contents of the file


#include <stdio.h>

int main
{
printf("Hello goons");
return 0;
}


Thanks to anyone who can be bothered to tell me.

kregg
Jul 29th, 2007, 03:14 PM
It was cat.

superbovine
Jul 29th, 2007, 11:28 PM
meow

tr333
Jul 30th, 2007, 04:35 AM
If you just want to print out the contents, cat is the best option. If you want to view a large text file one line at a time, then use the pager less (http://en.wikipedia.org/wiki/Less_%28Unix%29).

The cat command is not just used for printing out the contents of files. You can use it to pipe the file contents to another program, or even as a basic file splitting tool (in combination with the 'split' program).


$ split originalfile # split the file into multiple parts

$ cat part1 part2 part3 > originalfile # join the parts back together

wossname
Jul 30th, 2007, 07:20 AM
head or tail are also useful for dumping just the beginning or the end of the file.

head and tail have command line args for specifying how many lines to show.

see also tac and sort.

kregg
Sep 7th, 2007, 11:38 AM
Thanks for that guys. I'll be busy on Wikipedia now :D