Depending on his type of usage, an Ubuntu user may spend a lot of time in front of a terminal. Knowing some keyboard shortcuts can make you save a lot of time (ex: copy/paste text, move between the prompt text, etc).

So which bash tips/shortcuts do you guys know?

  • Are we really talking about "terminals" here or shells? There's a big difference. – Nathan Osman Mar 17 '13 at 23:00
  • I was asking for tips to help improve usage on gnome terminal or tty's ("black screens with a blinking cursor" :)). Would "bash shortcuts/tips" be more accurate? I have only used bash so I really don't know if those tips apply to other shells. – Salem Mar 17 '13 at 23:32
  • I'm really on edge about whether this should be closed or not... But I'll leave it open for now. – Seth Mar 18 '13 at 1:01
  • See this popular question for all manner of shortcuts, just like the ones mentioned here. – user76204 Mar 18 '13 at 1:38
  • Most of the shortcuts listed in the first answer below apply to Bash and not the terminal. – Nathan Osman Mar 18 '13 at 2:26

Output management

  • Shift+PageUp/Shift+PageDown - Scrolling the terminal output. This is very handy when using an tty: in Gnome Terminal works the same way as dragging the scroolbar.

  • Ctrl+s - Pauses the output: the command keeps running, only their output stops.

  • Ctrl+q - Resume the output: when output is paused, this will make the command show their output again.

  • Ctrl+l - Clear terminal output.

Prompt text manipulation

  • Ctrl+u - Deletes all the text currently typed in the prompt.

  • Ctrl+k - Deletes all the text from the right of the cursor

  • Ctrl+w - Deletes a word, from right to left.

  • Ctrl+a - Move to the beginning of the text.

  • Ctrl+e - Move to the end of the typed text.

  • Ctrl+Left/Right arrow - Move to the beginning/end of the previous/next word.

Command execution

  • Tab - Lists available commands from the typed text.

  • Up/Down arows - Shows previous/next command executed.

  • Ctrl+r - Searches the last command executed from the given text.

  • Ctrl+c - Stops the current command.

  • Ctrl+z - Sends the program to the background. Can then be managed using fg/jobs.

  • Ctrl+d - Logs out from the current terminal. Similar to typing exit.


There are many more, but ones I use a lot:

  • Repeat/insert the previous command: !!

    $ which rename
    $ file $(!!)
    file $(which rename)
    /usr/bin/rename: symbolic link to `/etc/alternatives/rename'
  • Select words from the previous command: !:1, !:2, etc.

    $ ls /var/lib/logrotate/*
    $ cat !:1
    cat /var/lib/logrotate/*
    ... contents ...
  • Fix typo in previous command: ^x^y and ^x

    $ lls
    lls: command not found
    $ ^l 
    ... listing ...
    $ ^s^l
    ... long listing ...

Not the answer you're looking for? Browse other questions tagged or ask your own question.