Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm learning how to use the shell. In playing around with some basic commands I encountered an issue. This is pretty basic stuff and I apologize if that upsets some folk.

On my desktop there exists a file called "myFirstShellScript.txt". In that file there is a string of text "show system".

So, if upon opening the shell I type cd desktop and then grep "show system" myFirstShellScript.txt" the shell returns the sentence where that string appears. Fine.

But I wanted to mess around. I then typed grep "show system" and hit enter. I wondered if grep would search the entire desktop since that was/is my pwd.

But what appears to have happened is that the terminal has stopped working. At first I thought it may just be busy searching but it's been a while. I then checked if other commands would work - pwd - does nothing, when I hit enter the cursor just moves to a new line.

I then tried to exit. I tried "exit", "end" and "quit". Nothing. The terminal window is not responding as expected.

I know I could easily just open another tab but wanted to ask what it is that I've done to the terminal here?

share|improve this question

migrated from Jun 4 '13 at 16:19

This question came from our site for professional and enthusiast programmers.

Hit Ctrl-C. This is not a programming question. – Sean Bright Jun 4 '13 at 14:58
up vote 3 down vote accepted

When you run grep, if you include a filename (grep pattern file), it searches that file. When you don't, it searches the standard input (stdin). If you include it in a pipe (foo | grep), it reads from the pipe. When you run just grep pattern, it reads input from the console. This is a very common pattern among Unix and Linux utilities. When you type exit, end, quit, or anything else, it compares it with the pattern and prints it if it matches, just as if you had given it a file. Try entering a line that matches the pattern - you'll see it echoed back to you.

To get out of this, hit Ctrl+D to signal the end of the file. Ctrl+C will kill most programs, but it's less clean than Ctrl+D.

share|improve this answer
Thank for the info Kevin. Now I know – Doug Firr Jun 4 '13 at 15:11

Grep without any arguments reads from the standard input, which is your terminal. It will keep on reading until it encounters the end-of-file character. The end-of-file character is Ctrl-D. Type that, and grep is done.

If that doesn't work, run stty -a and look for eof = ... to find your eof-character.

Gotcha alert: don't type Ctrl-D twice; the second one will be read by your shell. If it's your login shell it will think you're done and exit. Whenever your login shell exits (just like when you type exit) your login session is over and the login: prompt appears again. In other words, you are logged out.

share|improve this answer

Your Answer


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.