How do I close a file that I created using cat > command?

6

2

I learning how to use git on a Mac and I'm trying to add a file in one of my branches by using the "cat > " command. The problem I'm having is that I want to end editing the file in the terminal but I do not know how to close it. I'm guessing that I need to change "modes" for lack of a better term. How do I proceed?

lampShade

Posted 2010-10-11T22:48:56.063

Reputation: 449

I wouldn't rely on it all the time, but I don't see a problem doing that if all you want is to create a 2- or 3-line script. That's easier than firing up a text editor. – Charles Burge – 2016-11-30T22:51:07.513

3

cat is not a text editor! Are you trying to be a masochist? http://xkcd.com/378/

– Lie Ryan – 2010-10-11T22:57:25.970

Answers

13

Press Control-D.

nobody

Posted 2010-10-11T22:48:56.063

Reputation: 466

9

Type Ctrl+D at the start of a new line. ^D is the "end of file" character when typed from a keyboard.

Note that the ^D character itself is not entered into the file. The file ends just before the point where you type ^D.

Greg Hewgill

Posted 2010-10-11T22:48:56.063

Reputation: 5 099

at the start of a new line - because per POSIX, a line that doesn't end in a newline... isn't actually a line, so a file containing one isn't formally a text file. – underscore_d – 2016-10-02T13:46:06.613

The Enter shouldn't be pressed on Unix-based systems (though MacOS might be an exception?); this isn't DOS where you have to press Enter after ^Z. You may need to press ^D a second time if you aren't already at the start of the line, though. – Chris Jester-Young – 2010-10-11T22:53:47.847

Indeed. Why did I think you needed to press Enter? Fixed, thanks. – Greg Hewgill – 2010-10-11T22:56:38.017