Questions tagged [cat]

cat is a standard Unix utility used for concatenating files or printing specific file on the standard output.

cat is a standard Unix utility used for concatenating files or printing specific file on the standard output.

The cat program is given files in a sequence as arguments, it will output their contents to the standard output in the same sequence.

Examples

Printing the contents of a file on the standard output.

cat -n file.txt # n stands for line-numbers

Concatenating two files into third file:

cat file1.txt file2.txt > output_file

The purpose of cat is to concatenate (or catenate) files. If it is only one file, concatenating it with nothing at all is a waste of time, and costs you a process. This is also referred to as "cat abuse".

Nevertheless the following usage is common:

cat filename | command arg1 arg2 argn    
cat -- "$file" | grep -- "$pattern"
cat -- "$file" | less

can instead be written as:

grep -- "$pattern" "$file"
less "$file"

External reference

Further reading

684 questions
14
votes
4 answers

cat special characters meaning

with cat, I use the -A flag and I can't find what these characters mean anywhere. For example: cat /proc/cpuinfo > output cat -A output One of the lines is this: processor^I: 7$ I know the $ means new line, but what does ^I mean? What does ^@ mean?…
Ryan
  • 356
9
votes
2 answers

What is the difference in using Ctrl+D and Ctrl+C to terminate cat command?

I have the following two test files: test1 test2 Both of them are blank. Now I issue the following commands: $ cat > test1 Enter This is a test file Enter Ctrl + D $ cat > test2 Enter This is another test file Enter ^C Ctrl + C $ Now I…
Sonevol
  • 295
8
votes
2 answers

Terminal, won't execute any command, instead whatever I type just repeats

I need to open a file named -. (I am playing this hacker game) And when I try to use command cat -- - , after I type that, any command I type does not work, for that fact, everything I type just repeats itself after I hit enter. I assume I entered…
kakashi7593
  • 97
  • 1
  • 3
7
votes
5 answers

Cat with Headers and Line Numbers?

I have files like this $ cat trapetz x = 0:0.0001:7pi plot(x, sin(x).*cos(x)) Area = trapz(x, sin(x).*cos(x)) $ cat simpson f = inline(sin(x).*cos(x)); Area2 = quad(f, 0, 7pi, 1e-16) I want something like this $ cat -b -t MISSING? trapetz simpson…
user2362
5
votes
3 answers

merge file text with file name

I have two text files. The first "file1.txt" has content: Apple Orange Banana while the second file "file2.txt" has content: monday tuesday wednesday I want to combine them into one file and its output is: Apple File1.txt Orange …
5
votes
1 answer

Would cat *.txt concatenate files in alphabetical order?

Let's say that I have 3 files in a directory: apple.txt: apple beehive.txt: beehive zebra.txt: zebra If I concatenate this files with: cat *.txt > all_files.txt I do get: apple beehive zebra (I tested it on 5 files too, and I get the same…
Akavall
  • 233
4
votes
2 answers

Split and merge - with DVDs!

Say I have a large file called foo.tar.xz. I split the file into parts of just under 4.7GB each, using split -b 4689887232 foo.tar.xz foo.tar.xz., which gives me files named foo.tar.xz.aa, foo.tar.xz.ab, etc. Then I write each file to a different…
2
votes
2 answers

cat is stuck on a specific file

I have a python script that generates a file (cap.pcap). when I execute cat on it, it gets stuck forever (doesn't display anything). I tried to run: The commands file, hd and vi. They work properly. lsof and fuser, they show nothing. cp to another…
zeralight
  • 121
2
votes
2 answers

Joining files with cat confusion

If I do the following commands: $ cat picture.jpg > copy1.jpg and $ cat -v picture.jpg > copy2.jpg copy1.jpg is a perfect copy of picture.jpg, but copy2.jpg is a lot bigger than picture.jpg. I assume this is because copy2.jpg has had each of what…
EmmaV
  • 4,067
1
vote
1 answer

Where is cat command stored in linux?

I have visited usr/bin directory, but there's no file called cat. How can I find where cat file is stored? I also used Linux global search which did not work. Thanks
m0ss
  • 113
1
vote
1 answer

How can I prepend a header to a file when using cat?

If I have a file called test.php and its contents are $a = "apple"; echo PHP_EOL; echo " the value of \$a is $a" . PHP_EOL; I want to cat the contents of test.php to STDOUT but I want to add a header string
1
vote
2 answers

What happens when I cat a non-text file?

When I run cat on a file that isn't just text it returns a large amount of characters (many of which look like this ���). What is this data?
0
votes
2 answers

write contents of 2 files to another file

One of our scripts is writing contents of 2 files to another file, the below command takes 4 mins. File 1 has header record and file 2 has data of 4 GB. On file3 header record should be at top followed by contents of file 2. Is there a better way to…
Raghu
  • 1
0
votes
1 answer

Find a list of files and echo the file name and cat the file contents

I want to print the filenames and contents for each file in order. I tried this ls -1 after* | (echo;cat) - This only lists the files, does not cat the contents of the files. I also tried ls -1 after* | (echo; xargs cat) - This only cats the…
0
votes
1 answer

cat: -: Resource temporarily unavailable

I want to add some text to a file. Using the following command: $ cat > file And getting the following error: cat: -: Resource temporarily unavailable What is happening? how to debug this?
manish ma
  • 101
1
2 3