When I'm using tail -f and I want to return to the shell, I always use CTRL+C. Or when I am typing a command and feel like aborting it and starting over, I simply CTRL+C to get back to an empty command line prompt. Is this considered bad practice? I sometimes feel there might be a better way to break away from something, but really have no idea.

  • 6
    To cancel a partially entered shell command, you can use Control-U or Delete (depending on your tty settings and key bindings), but there's nothing wrong with using Control-C. Jan 21, 2012 at 20:56
  • @KeithThompson thanks for the Ctrl+U, I wasnt aware of that one :-)
    – phemmer
    Jan 21, 2012 at 22:47
  • For the record, C-u doesn't actually cancel the command entered, it moves it to the paste buffer (similar to the "cut" functionality of some programs).
    – Chris Down
    Nov 9, 2012 at 13:43

6 Answers 6


Ctrl+C sends a SIGINT to the program. This tells the program that you want to interrupt (and end) it's process. Most programs correctly catch this and cleanly exit. So, yes, this is a "correct" way to end most programs.

There are other keyboard shortcuts for sending other signals to programs, but this is the most common.

  • 9
    There's also Ctrl+D for programs that are reading input from the user. Ctrl+D closes STDIN to the program. For gracefully exiting the shell this is also available (exact same as typing exit).
    – phemmer
    Jan 21, 2012 at 22:48
  • 2
    @Patrick Ctrl+D actually sends an End of File indicator to the stream. It's up to the program to respond appropriately (usually closing the file stream).
    – Chris S
    Jan 22, 2012 at 2:32
  • thats what closing STDIN does. You cant get EOF without the pipe/stream being closed.
    – phemmer
    Jan 22, 2012 at 3:27
  • 9
    Wrong on three counts, Patrick. First: Control+D doesn't have this meaning for pipes. Second: the EOF special character doesn't close anything. It causes a one time return of zero bytes (presuming that the line buffer is empty) from the current read() system call. The next read()s are unaffected. Third: None of this applies to programs which put the line discipline into non-canonical mode, such as most shell programs from the past couple of decades and indeed any other program that uses a library such as GNU readline.
    – JdeBP
    Jan 22, 2012 at 11:32

This method is just fine, really.


To abort a long command while typing, I sometimes jump to the start of line, and insert a comment sign, before hitting enter:



This is useful, if I typed a copy command with a long path, for example, and meanwhile observe, that I first need to create the directory, but would like to repeat the command afterwards. Then I just have to take it from the history, delete the hash, and enter it.

In Bash, you can use the shortcut


to remarkify your command, as pointed out in the comments (Thanks, @Zorawar).

  • 6
    You can also use Ctrl-A without taking your fingers off the home row. Jan 22, 2012 at 3:30
  • 1
    And Ctrl-E goes to the end, by the way.
    – Dave
    Jan 27, 2012 at 18:15
  • @Dave: That's right, but you don't need to move to the end to hit enter, to confirm your command. The commandline is not an editor, where this might insert a newline. Jan 27, 2012 at 20:12
  • 2
    In bash you can achieve the same thing by just pressing Alt-#: it will put the comment in and run the command (so putting it in your history).
    – Zorawar
    Jun 6, 2015 at 14:50

Generally speaking, using Ctrl+C is fine when the program offers you no interactive way to terminate (either by design, or, more frequently, because it has frozen or become unusable). Just bear in mind that, when in interactive mode, the key combo you really want may be Ctrl+D, which sends an EOF, signaling the end of the input.


If using Bash, one can also use Ctrl-Z, and type bg to "put the current job in background".


As @Patrick said in the comment on the accepted answer,

There's also Ctrl+D for programs that are reading input from the user. Ctrl+D closes STDIN to the program.

This helped me when Ctrl+C did not work to get the command line back after using >>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .