On bash command-line, how to delete all letters before cursor?

BashCommand Line

Bash Problem Overview


On bash command-line, how to delete all letters before cursor? I know Ctrl-k deletes all afterward the cursor.

Bash Solutions


Solution 1 - Bash

Ctrl-u - Cut everything before the cursor


Other Bash shortcuts,

  • Ctrl-a Move cursor to beginning of line
  • Ctrl-e Move cursor to end of line
  • Ctrl-b Move cursor back one word
  • Ctrl-f Move cursor forward one word
  • Ctrl-w Cut the last word
  • Ctrl-k Cut everything after the cursor
  • Ctrl-y Paste the last thing to be cut
  • Ctrl-_ Undo

And discover more via man page for bash shell: man bash

Additional bash command-line shortcut cheat sheet: http://www.bigsmoke.us/readline/shortcuts

See the documentation here: http://www.gnu.org/software/bash/manual/bashref.html#Commands-For-Killing

Obligatory: Learn more about Bash, Linux, and Tech through Julia's comics: https://twitter.com/b0rk/media

Julia on Bash

Solution 2 - Bash

In zsh, Alt+w clears all characters before the cursor.

In contrast to bash this does NOT cut them; it just deletes them.

This applies to zsh's Emacs mode (which is the default), NOT to Vi mode.

Solution 3 - Bash

The hotkey Ctrl+U should do this for you.

Solution 4 - Bash

Ctrl+x backspace clear all entry before cursor current position

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionqazwsxView Question on Stackoverflow
Solution 1 - BashMayuraView Answer on Stackoverflow
Solution 2 - BashxjclView Answer on Stackoverflow
Solution 3 - Bashmjgpy3View Answer on Stackoverflow
Solution 4 - BashSaeed AlizadehView Answer on Stackoverflow