Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
3  
cat 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 Jun 2 '10 at 11:20
    
Ah, this did it for me, thank you! –  Yakattak Jun 2 '10 at 11:23
1  
@Darth - You should write your comment as an answer instead. –  Nifle Jun 2 '10 at 11:56
    
"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 Jun 2 '10 at 21:56

2 Answers 2

up vote 5 down vote accepted

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

share|improve this answer

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

share|improve this answer
    
I see, how can I get ^D? Or what is the shortcut or whatever? –  Yakattak Jun 2 '10 at 11:17
    
It is the key combination ctrl + d. –  ayaz Jun 2 '10 at 11:29
    
Worth noting that lots of *nix command line apps (all the ones that read input from stdin) work the same way. –  Chris Nava Jun 2 '10 at 17:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.