On bash command-line, how to delete all letters before cursor? I know Ctrl-k deletes all afterward the cursor.
            Asked
            
        
        
            Active
            
        
            Viewed 1.9k times
        
    59
            
            
        - 
                    1[Related question](http://stackoverflow.com/questions/9679776/how-do-i-clear-delete-the-current-line-in-terminal). – Thor Sep 08 '12 at 23:26
- 
                    [Readline](https://tiswww.case.edu/php/chet/readline/rluserman.html) handles the keyboard shortcuts. See also `man 3 readline`. These apply to very many ineractive command-line tools, not just bash. – Jack Wasey Apr 14 '22 at 09:57
3 Answers
109
            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
 
    
    
        Mayura
        
- 1,879
- 1
- 19
- 21
- 
                    7
- 
                    1Where is the "official" documentation about these? Why you only show fish without showing how to fishing? – qazwsx Sep 08 '12 at 21:35
- 
                    @Problemania I've added a link. In general, man or info pages are a good place to start, try running the command `man` followed by the name of the unix tool you're using (eg `man bash`). – John Carter Sep 08 '12 at 21:40
- 
                    I know about `man`. How can you find info about the above commands in `man bash`? I tried and couldn't. – qazwsx Sep 08 '12 at 21:42
- 
                    1Yeah, for GNU stuff (such as bash), `info` pages can be more complete - that's what the link I posted in the above answer goes to. To get this from the command line use `info bash` -> Command Line Editing -> Bindable Readline Commands -> Commands for Killing. – John Carter Sep 08 '12 at 21:46
- 
                    Actually, though the above is in `man bash` for me as well (use `/` to search for text). – John Carter Sep 08 '12 at 21:48
- 
                    4
- 
                    2
- 
                    thank you so much for this info. I didnt know bash had its own man page – lollerskates May 14 '18 at 17:18
- 
                    2@qazwsx For at least some of this, GNU readline is the relevant software, maintained by the GNU bash maintainer, and in step with it. See https://tiswww.case.edu/php/chet/readline/rluserman.html . Also `man 3 readline` is full of exotica. – Jack Wasey Apr 14 '22 at 09:50
- 
                    
17
            
            
        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.
 
    
    
        xjcl
        
- 12,848
- 6
- 67
- 89
- 
                    Actually, I did recently learn that bash does 'cut' when readline (not bash, actually) deletes. On my Linux machine now, in bash, I can cut back a word with control+W and "yank" it back with control-Y. Many vexing and obscure key combos are there, but learning the big hitters is already useful when working in a shell. (If you dare to use vim mode for readline, you can have yank with a different meaning.) My head hurts, but cursor keys are less worn. See https://tiswww.case.edu/php/chet/readline/rluserman.html – Jack Wasey Apr 14 '22 at 09:55
 
    
