2

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?

Salem
  • 19,744

2 Answers2

4

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.

Salem
  • 19,744
3

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

  • Repeat/insert the previous command: !!

    $ which rename
    /usr/bin/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/*
    /var/lib/logrotate/status
    $ cat !:1
    cat /var/lib/logrotate/*
    ... contents ...
    
  • Fix typo in previous command: ^x^y and ^x

    $ lls
    lls: command not found
    $ ^l 
    ls 
    ... listing ...
    $ ^s^l
    ll
    ... long listing ...
    
zwets
  • 12,354