Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In bash emacs mode, is there anyway to delete till the previous slash character? For example if i entered the command cp /usr/local/bin/reallylongincorrectfolder /home/myname/reallylong_and_correct_path and want to just delete the reallylongincorrectfolder.Is there any shortcut? This is a very comman scenario for me in bash. Something like dF<char> in vi?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Alt-Backspace and Ctrl-w are commonly mapped to backward-kill-word, which does that. If you want to find out what it's mapped to on your system (if anything), run bind -P | grep '^backward-kill-word'.

As explained by @Barmar, this is different from unix-word-rubout, which removes to the previous space boundary.

share|improve this answer
    
But that will kill the entire word.. I want to kill only till the last slash –  MIkhail Jun 11 '13 at 8:59
    
It does remove only to the last slash here. Slash is one of the default word separators. Are you sure you're using Bash? –  l0b0 Jun 11 '13 at 9:01
    
My bad.. Alt-Backspace does remove it till the last slash.What is the difference between ALt-BackSpace and Ctrl-W ? –  MIkhail Jun 11 '13 at 9:47
3  
Ctl-w is normally bound to unix-word-rubout: Kill the word behind point, using white space as a word boundary. –  Barmar Jun 11 '13 at 10:31
    
This doesn't exactly work. "Words are composed of alphanumeric characters (letters and digits)". Hence it'll stop at much more than just slashes. The default-unbound unix-filename-rubout is slightly better, since it'll stop at white space and slash. –  Sparhawk May 4 at 1:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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