Linux control sequence tricks

Linux control sequence tricks

Ben Patterson / IDG

You may have never tried ctrl-u. This control sequence and its “partner in crime” ctrl-y work together in an interesting way. The ctrl-u sequence removes the text you’ve just typed from command line and places it in something of a clipboard while ctrl-y puts in back. So, when you’ve just typed a complicated command, but not yet hit return, and then realize that you need to run some other commands first, you can save the command you’ve typed, take care of whatever other commands you need to run and then yank the command you saved back into place.

$ gensched 07-2018 IT summary^u <== typed line will disappear
$ update cal 07-2018            <== run some other commands
$ schedCheck
$ ^y <== "gensched 07-2018 IT summary" reappears

The ctrl-s and ctrl-q sequences also have a working relationship. Where ctrl-s freezes your screen, ctrl-q allows the display to continue rolling again.

$ bin/loop
^s    <== movement stops and waits

The ctrl-z sequence suspends the current process. You can bring it back to life with the fg (foreground) command or have the suspended process run in the background by using the bg command. If you then want to stop the process, you’ll then have to list your background processes with the jobs command and use kill (e.g., kill %1). Don’t forget the % that specifies the process by job number rather than its PID.

$ bin/loop
[1]+  Stopped                 bin/loop
$ bg
[1]+ bin/loop &
$ sleeping
[1]+  Running                 bin/loop &
$ sleeping
$ kill %1

The ctrl-h, ctrl-w and ctrl-u sequences erase (i.e., back over) the last letter you just typed, the last word that you just typed, or the entire line.

The ctrl-a and ctrl-e  will move your cursor to the beginning or end of the text you have just typed.

The ctrl-r sequence allows you to easily rerun recently entered commands. Type ctrl-r followed by the beginning of the command that you want to rerun. The command run will be the most recent one that began with the letters you enter.


  • How to use shortcuts in your favourite apps

  • Computerworld Cheat Sheet - Microsoft Excel 2016

    Excel 2016 cheat sheet

  • Microsoft Word 2013: Cheat Sheet

    Word 2013 cheat sheet

  • template c100.00 01 16 36.still001

    2-Minute Linux Tip: How to use the top command

Control sequences can be handy if you can keep them straight. Here’s a quick rundown of the control sequences just covered:

    interrupts the running program
    suspends the running program
    freezes the screen, stopping the display
    thaws out the screen and allows the screen display to continue
    deletes the last character typed
    deletes the last word typed
    deletes the last line typed
    retrieves previously run commands so you can run them again
    removes text from the command line and places it in the clipboard
    grabs text from the clipboard and runs it
    clears the screen
moves cursor to the beginning of the line
moves cursor to the end of the line

The only difficult part of using control sequences is remembering which does what. For some, the letter suggests the control sequence function. For others … well, not so much. But they can all be very useful.