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.
|
|
|||||||||
|
migrated from serverfault.com Jan 21 '12 at 21:07
|
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. |
|||||||||||||||
|
|
To abort a long command while typing, I sometimes jump to the start of line, and insert a comment sign, before hitting enter: Home#Enter Pos1#Return 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. |
|||||||||||
|
|
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 |
||||
|
|
|
If using Bash, one can also use Ctrl-Z, and type |
|||
|
|