cat is a Unix utility used for concatenating files.

learn more… | top users | synonyms

-1
votes
3answers
42 views

cat /dev/null emptied my log file but size did not change

I'm quite new to Unix. Using Solaris 10 I faced the below issue. There is a large log file with size 9.5G. I tried to empty the file using the below command. # cat /dev/null file_log.txt By doing ...
4
votes
2answers
43 views

How to pipe a remote file to stdout over scp or sftp?

Using ssh, it is easy to print the contents of a file using ssh host 'cat file.txt' When ssh is disabled, and only SFTP is enabled, running the previous command gives the following error: ...
3
votes
1answer
46 views

Does cat never read from terminal?

Chapter 43. Redirecting Input and Output of Unix Power Tools, Third Edition has to say this about cat command: Standard input (stdin) normally comes from your keyboard. Many programs ignore ...
4
votes
2answers
95 views

(cp is to cat AS mv is to ?) mv multiple files into one file instead of cat * rm *

For everything in this question pretend the system only has one disk and filesystem. (we are not writing to different partitions, disks or filesystems) I am working on a project that cats very large ...
2
votes
2answers
48 views

Backed up over wrong hard drive

I've just written over the wrong hard drive using the command: sudo sh -c 'pv /dev/sdb >/dev/sdc' How do I go about undoing this? I was creating the first even backup of the drive, and I backed ...
0
votes
2answers
23 views

concatenate .out files

Can I combined multiple .out files with the cat command in bash or csh? Additionally I want only the header of first file to be concatenated and I was thinking of using the tail function for that. ...
3
votes
1answer
53 views

How to set default tabs only for cat?

I prefer to set tabs 4 however this may have some side effects, such as for example ls out put may look not properly aligned. How might I configure the terminal / cat to use four spaces for tabs for ...
2
votes
1answer
102 views

How to interleave the lines of two or more files?

I have tried to get the 2 files output in a single file. I have tried below command: cat file1 file2 but here file2 data is appending to file1. What I need is file1 1st line followed by file2 ...
14
votes
2answers
1k views

How do I “cat and follow” a file?

A file is being sequentially downloaded by wget. If I start unpacking it with cat myfile.tar.bz2 | tar -xj, it may unpack correctly or fail with "Unexpected EOF", depending on what is faster. How to ...
4
votes
2answers
72 views

continuous reading from named pipe (cat or tail -f)

I have configured rsyslog to log certain log events to /dev/xconsole: *.*;cron.!=info;mail.!=info |/dev/xconsole /dev/xconsole is a named pipe (fifo). If I want to see what is being logged, I ...
0
votes
2answers
44 views

Passing a variable to a bash script that uses 'EOF' and considers the variable a literal [closed]

in this script i end up with "$1" being saved to the /test file. #!/bin/bash cat > /test << 'EOF' $1 EOF the truth is.. i need to keep 'EOF' as 'EOF' because my argument($1) contains ...
2
votes
2answers
99 views

“cat” command: how to automatically escape everything that might be a violation?

If you copy the contents of httpd.conf and then paste it into a cat command.. such as this one.. #!/bin/bash cat > /test << EOF pasted here.. EOF you run into this error: -bash: ...
4
votes
6answers
883 views

How to tell “cat” command to not hang on when there is no path provided?

I am simply trying to get a bash script to return the content of a text file. #!/bin/bash cat $1 the problem is.. when the path to a file is not fed to this bash script... how will it even close ...
0
votes
3answers
52 views

How to fork a “cat” command?

This is my bash script. #!/bin/bash oo="`cat /etc/httpd/conf/httpd.conf`"; cat > /a.txt << EOF $oo EOF it simply reads /etc/httpd/conf/httpd.conf and writes it to /a.txt, the problem has ...
15
votes
5answers
409 views

Is it possible to make zcat output text even if it's uncompressed? [duplicate]

The problem is I have some database dumps which are either compressed or in plain text. There is no difference in file extension etc. Using zcat on uncompressed files produces an error instead of the ...
10
votes
5answers
977 views

Difference between cat and '>' to zero out a file

Are these two commands any different on how they go about zero-ing out files? Is the latter a shorter way of doing the former? What is happening behind the scenes? Both $ cat /dev/null > ...
1
vote
1answer
120 views

Difference between cat * and cat * >>

To merge multiple files in a dir I have tried: cat * myfile.log but this seems to just merge line and line and is thus very slow So using instead: cat * >> bigfile merges the files much ...
0
votes
1answer
43 views

removing the last line of a file not working? [duplicate]

I have this TXT file that is created by a bash script and at the end I want to remove the last line of that file that is an empty one. head --lines=-1 r3.txt > r4.txt sed '$d' r3.txt > r4.txt ...
0
votes
0answers
70 views

cat echoes to serial port

Connecting my Windows PC to a Linux system (Wheezy) via the serial port (RS232) basically works except one problem when sending a message from the the PC terminal the Linux system. The reception of ...
4
votes
1answer
204 views

How can I get less or cat to use color in the output from .cat of my .bashrc, similar to vi 'ing it?

When I vi my .bashrc file it is colorized, i.e. but when I cat or less the file I get all white, i.e. How can I get cat (and less) to have color? cat does have color for my ruby .rb files but ...
4
votes
2answers
124 views

Spliting `File` and `directory name with space' via shell script

I've got a file called Files.txt having following content: TestApp/Resources/Supporting Files/main.m TestApp/Resources/Supporting Files/AppDelegate.h TestApp/Resources/Supporting Files/AppDelegate.m ...
8
votes
4answers
581 views

Why does “cat ttyUSB0” not produce output?

I connected an infrared receiver to a USB port ... (the last line of dmesg tells device file) $ dmesg [10496.596063] usb 7-2: new full-speed USB device number 2 using uhci_hcd [10496.751112] usb 7-2: ...
1
vote
2answers
223 views

Why using cat on binary files messed up the terminal and how?

If I understand correctly the cat manual: concatenate files and print on the standard output cat will take files as argument and print them on standard output. What I don't get is if I use the ...
9
votes
2answers
1k views

Fastest way to concatenate files

I've got 10k+ files totaling over 20GB that I need to concatenate into one file. Is there a faster way than cat input_file* >> out ? The preferred way would be a bash command, Python is ...
2
votes
1answer
67 views

< and << in UNIX /Linux

What is the option <<and < are used in linux for??? For example cat << abc.txt I know its a stupid question, but i was not able to search it on google as i did not know what ...
1
vote
1answer
94 views

Cat and Less give different output

I executed the following command # top > /home/user/top_output.txt Nothing Happened for a while and then i pressed Ctrl+C. When i checked the file that was created, it had the contents in it. So ...
2
votes
2answers
394 views

How can I get the tac command on OS X?

I like to use tac to reverse the output of cat. However, it's not available in the Mavericks terminal. I tried to find it on MacPorts and again it's not available. Can anyone please show me how to get ...
0
votes
2answers
259 views

How can I concatenate all files in a directory together in one command line operation? [duplicate]

I have 1000 csv files in a directory. I would like to concatenate them all together in order. They are named img_size_1.csv to approx img_size_1000.csv This answer is close but assumes a list file. ...
8
votes
4answers
1k views

Grep from the end of a file to the beginning

I have a file with about 30.000.000 lines (Radius Accounting) and I need to find the last match of a given pattern. The command: tac accounting.log | grep $pattern gives what I need, but it's too ...
2
votes
1answer
427 views

cat file to udp, pt 2: send 1 udp packet per ^C-delimited line

Yesterday I asked a question about catting a file over a UDP socket in bash. The solution we came up was netcat -c -w 1 -v -u -s 127.0.0.1 239.255.0.1 30001 < test.txt. This worked in the sense ...
2
votes
1answer
133 views

cat file to multicast

I have a text file (test.txt) which represents captured network data. The actual protocol is text-based, with NULL line endings, so this isn't a problem. I need to run this test captured data ...
0
votes
1answer
102 views

Passing multiple scripts to shell over ssh

I have a somewhat lengthy script which sources other scripts to include the functions there. I'd like to execute this script remotely via ssh. Now I thought to make one script file of it (without ...
2
votes
3answers
557 views

Can't cat a file or make a directory: contradictory output?

I am getting output from a terminal in Ubuntu 12 that I don't understand. $cat sublime no such file or directory $mkdir sublime cannot create directory 'sublime': File exists How can both of these ...
8
votes
1answer
795 views

How to store an image file in bash variable?

After I use the following command, pngString="$(cat example.png)" echo -n "$pngString" > tmp.png I can't open the tmp.png as a PNG file. Maybe some information is lost when I use $pngString ...
3
votes
2answers
296 views

How to highlight a word in the output of “cat”? [duplicate]

I can do the following to see if some word is available in the output of "cat": cat filename | grep word This filters the output and shows only those lines which contain "word". Now, is it possible ...
8
votes
3answers
383 views

Why does the less-than sign not work as a replacement for cat in bash?

I heard about "useless use of cat" and found some suggestions, but the following outputs nothing in my bash shell. < filename Using cat works as expected though. cat filename I'm using Fedora ...
1
vote
1answer
127 views

Cat write text with “$” inside

I want to write configuration information to a specific file which has dollar signs ($) inside. That seems to be a problem. Here's what I did: $ cat >> /etc/nginx/nginx.conf <<EOF # For ...
2
votes
2answers
360 views

How to mount bzip2-ed Clonezilla image without using extra drive space?

My hard drive seems to be failing and I suspect some data may be already damaged, so I decided to make an entire drive backup with Clonezilla using dd. I have chosen bzip2 compression to fit entire ...
0
votes
2answers
45 views

Concatenate a folder's Java files, with a header for each file

I have an obligation to provide a document which just contains every source code file, with the file's name before each file. Example: ============================= src/com/example/Factory.java ...
3
votes
4answers
141 views

saving output of another command

I need to select certain lines from the log file and also save them to a text file. I tried the following but none of them are working as expected. The file "todel.txt" shows 0 bytes. tail -f ...
3
votes
1answer
114 views

How can i colorize cat output including unknown filetypes in b&w?

I like the colors I have in vim. Can I get my output similarly colorized when I do a cat? I like that I can use the colorize tool as in Colorized `cat` for source and script files?. I would like that ...
0
votes
0answers
38 views

How to `cat` file with syntax highlight? [duplicate]

In my hello.c: /* Hello World program */ #include main() { printf("Hello World"); } How can i cat this file on terminal with syntax highlight?
4
votes
1answer
1k views

How to echo variables using cat into file?

I have simple script like this: #!/bin/bash BOO=bla-bla-bla cat > ./Makefile <<'EOF' Hello INCLUDES := -I/data/opt/include/ -Ideps/ -I$BOO/include EOF Yet it outputs into ...
2
votes
3answers
155 views

Concatenate files in multiple matching subdirectories

I need to concatenate files based upon the name of the subdirectory they are in. The subdirectories sometimes have duplicates and sometimes don't. The file structure looks like this: RootDir 633 ...
5
votes
2answers
235 views

A virtual file containing the concatenation of other files

Is there a way of creating a filesystem object akin to this: mknod files p cat file1 file2 ... fileN > files but such that it can be seeked in, as if it were a regular file?
16
votes
2answers
448 views

Why does this command create an enormously large file?

I was experimenting today with some append operations and, in my curiosity, ran this (where file1.txt was non-empty and file2.txt was empty): $ cat file1.txt >> file2.txt >> file1.txt ...
6
votes
1answer
848 views

How do you use output redirection in combination with here-documents and cat?

Let's say I have a script that I want to pipe to another command or redirect to a file (piping to sh for the examples). Assume that I'm using bash. I could do it using echo: echo "touch somefile ...
1
vote
2answers
160 views

Why the inconsistency with using cat vs. echo piped to this sed command?

Inspired by this question: sed: N command does not read single line I wanted to understand why there appears to be an inconsistency between the following 2 commands: #1. echo This command produces ...
2
votes
3answers
335 views

hardlink/softlink multiple file to one file

I have many files in a folder. I want to concatenate all these files to a single file. For example cat * > final_file; But this will increase disk space and also will consume time. Is there is a way ...
2
votes
2answers
68 views

No result when using Multiple write file & sed in shell script

I would like to swap variables from old file to new file when I use single line like this cat ../oldFile.html | sed "s@$dayMaxInNew@$dayMaxIn@g" > newFile There's result from newFile. But When ...