Computing.Net > Forums > Unix > Unix CAT Command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix CAT Command

Reply to Message Icon

Name: Jome
Date: October 20, 2002 at 20:11:27 Pacific
OS: HP Unix
CPU/Ram: HP PARISC 8500
Comment:

Hi.

Hope you could help me answer the following:

1. How does cat command works? Does the cat command read all the files first before copying to the output file or read the files per batch then copy to the output file?

2. Does cat command make use of other processes? Meaning if we issue the cat command in the Unix prompt, do other processes stops?

3. What's the maximum capacity of a single file (debug file) in Unix? Given the scenario that all debug files are open, does a single output file can accomodate the contents of all debug files?

4. Is the cat command dependent on the capacity of the files to be concatenated? Meaning, the bigger the file, the slower it would be for the cat command to finish the operation?

5. Given the maximum capacity of a single debug file, how long would it take for the cat command to finish the operation?

Also, make I ask any cautions that I should remember in using the cat command.

Hope to get feedback from you soon

Thank you.



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: October 20, 2002 at 22:02:32 Pacific
Reply:

Question four makes it sound like you believe that the 'cat' command concatenates files. That is not specifically true.

The cat command reads the file (or files) on it's command line and echos the file contents to standard out.

If you list multiple files on the command line and redirect the output to a single file, then you do, in effect, concatenate the files, but that is a result of how you used the command, not it's sole purpose.

I didn't write the 'cat' command nor have access to its source code, so these answers are based upon logic and my use of the 'cat' command.

Question 1 - it's highly unlikely that the cat command reads all of the files or even all of one file before it starts echoing to standard out. That would be highly inefficient and serve no purpose. Most likely it reads one line, outputs the line, then reads the next line. Reading entire files would mean that it would have to have a memory buffer large enough to hold the entire file. And there is no reason to have the entire file in memory at once.

Question 2.
Unix is a multi-user, multi-process system. Running a single process rarely effects other processes.

Question 3.
I'm not a sys admin type, but I believe that the size of a file is limited only by the amount of disk space available in the file system that the file resides in. Many times I've seen run-away processes fill their log file until file system is full. At this point, things usually start crashing or locking up.

I'm not sure I understand the second question. I think that you are asking if all of the log files can be copied to a single file. It depends on the size of all of your log files and the amount of hard drive space you have.

Question 4
Obviously, the larger the file the long the cat command will take. If I asked you to shovel two cubic yards of dirt and then asked you to shovel two cubic miles of dirt, would you do both in the same amount of time?

Question 5
This would depend upon your system speed, disk speed, hard drive fragmentation, size of file, etc.

The only caution that I can give, is don't drop your cat in the bathtub with a toaster. It'll run out of lives quick.

The cat command is pretty innocuous. It would be pretty hard to mess up stuff using the cat command. The only thing that I can think of is 'cat'ting a file and redirecting the output back to the same filename (cat myFile >myFile). That may cause problems.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix CAT Command

Unix stat command www.computing.net/answers/unix/unix-stat-command/5869.html

Unix sed command problem www.computing.net/answers/unix/unix-sed-command-problem/5822.html

unix command help www.computing.net/answers/unix/unix-command-help/6321.html