I know I can delete backward one word at a time, but many times I just want to change part of a path. Is there a command in emacs and therefore keyboard command in bash to delete backward just until a slash?

alt+w does one word at a time: How can I delete a word backward at the command line (bash and zsh)?

  • 3
    As you are talking about a path, I suppose you mean slash, not backslash
    – Philippos
    Mar 30, 2022 at 9:28
  • @Philippos. yep, edited.
    – alchemy
    Mar 31, 2022 at 23:17

3 Answers 3


Well, I realized a simple solution.. basically to use ctrl+left-arrow to skip back to the point I want to change. Then press ctrl+k to delete forward.

(just an aside, ctrl+left-arrow doesnt always work on some terminals, GCP remote ssh shell for example, and I wonder why)

  • Depending on the terminal emulation used, the left-arrow-key may be sent as some escape sequence or as cltr-H (backspace), causing problems when trying to send ctrl-ctrl-H
    – Philippos
    Mar 30, 2022 at 9:52

If you are in vi mode (set -o vi), you do Esc to return to normal mode, then db (delete to beginning).

If you are in emacs mode (typically the default), you can do CtrlR for backwards search, then / to search for the slash, finally altd to delete forward.

  • interesting.. good to know that Ctrl+R searches also searches the current line when there is one.
    – alchemy
    Mar 31, 2022 at 23:25

From what I understand, you want to properly configure GNU-readline (which handles text edition at GNU-bash's prompt)

In Bash, you can type

bind '"\ew": backward-kill-word'

Then test.

To make this permanent, as a user, you can edit ~/.inputrc, which takes priority over the system config in /etc/inputrc. You can $include /etc/inputrc in ~/.inputrc to inherit from it.

You want to have this line:

"\ew": backward-kill-word

This often defaults to unix-word-rubout, or even a shell or bash prefixed macro, which takes only white space as a delimiter. But backward-kill-word will take anything that is "not a letter nor a digit".

Refer to man 3 readline for full documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .