Questions tagged [cat]

cat is a command-line utility used to concatenate or copy the contents to standard output from a file or standard input (if no file name is passed).

cat is a command-line utility provided by GNU Coreutils which can be used to concatenate the content to standard output from a file or standard input (if no file name is passed).

To print the content of a file (let's say, ubuntu.txt), use:

cat ubuntu.txt

Details about the options/flags for cat can be found in the manpage.

On systems like MS-DOS that distinguish between text and binary files, cat normally reads and writes in binary mode. However, cat reads in text mode if one of the options -bensAE is used or if cat is reading from standard input and standard input is a terminal. Similarly, cat writes in text mode if one of the options -bensAE is used or if standard output is a terminal.[source]

117 questions
50
votes
1 answer

omit filenames in grep

I am greping a string from multiple files, but the one undesired side effect, is the filename prefacing the output. How can I suppress the filename outputs using only grep? $ grep -i lp lpNet* lpNet:This was printed via the internet using the lp…
j0h
  • 15,413
50
votes
9 answers

Can `cat` show files using code markup in colors?

Sometimes I quickly want to view the contents of a file from the command line. For this I of course use cat , but it is often source files in Python , Java or simple HTML . For these files it would be handy if cat could give some color markup to the…
kramer65
  • 2,213
32
votes
5 answers

What is the difference between "cat < filename" and "cat filename"?

The simplest way to display file contents is using the cat command: cat file.txt I can get the same result using input redirection: cat < file.txt Then, what is the difference between them?
BlueSkies
  • 2,395
23
votes
2 answers

How to use `cat` to see the top of a very long file?

I'd like to know how to cat my-verylong-file and show it from the top instead of the end. Like the man command does.
IDK
  • 603
23
votes
2 answers

What's wrong with my cat command?

I lent a friend a computer with Ubuntu 12.04 LTS on it, and he messed up the cat command. $ cat testfile.txt cat: meow! $ Can someone tell me how to fix this? please? Output of which cat : /bin/cat
TheDoctor
  • 349
21
votes
4 answers

What is 'cat' used for?

I've seen the cat command come up in some online stuff and I was curious as to what cat did and what it's for in the context of someone who is just doing some simple command line stuff.
cosmoflop12
  • 1,199
  • 3
  • 15
  • 24
19
votes
5 answers

Appending a line to a file in the cat command?

I can do cat file.txt to get the contents of a file but I also want to tack on a final line of my own choosing. I tried piping (cat file.txt ; echo "My final line") | but only the final line is getting passed through the pipe. How can I join the cat…
18
votes
2 answers

When run cat says: "Hello, nothing to see here! Move along!"

PLEASE NOTE: To view the comments on this and the extended discussion on this, which includes all that has been tried, please look at this chat room . Today when I ran the cat command, instead of the contents of a file, I got: Hello, nothing to see…
user364819
14
votes
1 answer

How do I 'cat' a text file but start from the bottom instead of top

I have a very big text log file of about 37MB. Using cat file | more I can view the file contents one page at a time. The problem is that this always starts from the top - the old entries. How can I make it start from the bottom where the newer…
Parto
  • 15,685
10
votes
3 answers

cat command doesn't show the lines of the text

i am trying to read an odt file from terminal. When i type cat myfile.odt it shows me an image like this
Angelos G
  • 109
9
votes
3 answers

Difference between cat and sudo cat?

Can you tell me what the difference is between cat and sudo cat ? All I know so far is that cat is used for displaying contents of file and concatenation.
Edison
  • 367
8
votes
1 answer

How to use the cat command to find a specific word in a textfile

I did some research but I was unable to find anything to help, I need to find the word "war" in a text file, I know that I can use the cat command, but I need to modify it somehow, can someone help?
8
votes
4 answers

How to replace cat with bat system-wide Ubuntu 22.04

I am using Ubuntu 22.04 with bash, pretty vanilla, and have added alias cat="batcat" to ~/.bashrc . The program batcat or bat being referred to can be found here: https://github.com/sharkdp/bat So, when I run cat ~/.bashrc , for instance, it outputs…
WhiteBerry
  • 125
  • 1
  • 6
7
votes
1 answer

How to unzip only the first few lines of a zip archive?

I have a zipped text file a.zip I want to read the first 10 lines of it. Is it possible to do that without unzipping the whole file?
6
votes
2 answers

I just ran cat /dev/zero and now cat is hanging

I ran cat /dev/zero and it now just hangs whenever I run a cat command. I pressed Ctrl + C to stop that command. Have I broken something, and how can I fix it?
Tim
  • 33,510
1
2 3 4 5 6 7 8