cat on Mac OS X never exits

3

I'm a bit of a UNIX noob, but I'm trying to run the cat command to make a simple text file and it works great, however cat is never exited after making the file. For instance, I type cat > ~/mytextfile.txt and hit enter, the file is created but my cursor remains on a blank line.

skylerl

Posted 2010-06-02T11:10:53.230

Reputation: 160

3cat is most often used for dumping the contents of one file into another, ex. cat file1 > file2 or feeding a file to a pipe, ex. cat file | somecommand. If you simply want to create an empty file, use the command touch. If you wish to create a new file with a few simple words, or append a few lines to an existing file, echo is a common solution. – Darth Android – 2010-06-02T11:20:16.563

1@Darth - You should write your comment as an answer instead. – Nifle – 2010-06-02T11:56:27.443

"feeding a file to a pipe, ex. cat file | somecommand" 'cat'ting in this context, though commonly done, is completely useless. 'somecommand <file' is equivalent and runs one less process. The only way it might make sense would be to concatenate several files into a single input stream for 'somecommand' – JRobert – 2010-06-02T21:56:23.040

Answers

7

You're telling cat to send nothing to a file. Use touch (as mentioned) instead.

Josh K

Posted 2010-06-02T11:10:53.230

Reputation: 11 754

9

You have to send an EOF (^D) character on the standard input to tell cat to stop.

ayaz

Posted 2010-06-02T11:10:53.230

Reputation: 8 106

I see, how can I get ^D? Or what is the shortcut or whatever? – skylerl – 2010-06-02T11:17:50.953

1It is the key combination ctrl + d. – ayaz – 2010-06-02T11:29:40.190

1Worth noting that lots of *nix command line apps (all the ones that read input from stdin) work the same way. – Chris Nava – 2010-06-02T17:45:59.900

0

In my MAC I need to send EOF (^D) twice.

Example:

cat > /tmp/mypassword
RandomLettersAndNumbers123

Then press FN + Control + D twice.

gogasca

Posted 2010-06-02T11:10:53.230

Reputation: 103