$ ln -s ./dir/target.txt /path/to/source.txt{cursor here}

How do swap file typed filenames in command line? Alt+T swaps words, not filenames, resulting in ln -s ./dir/target.txt /path/to/txt.source.

Ideally the solution should also interpret "filenames with quotes.txt" correctly.

Can it be done by some readline and/or bash configuration, or by some clever use of existing shortcuts?


Partial answer based on this. {} denotes cursor:

$ ln -s ./dir/target.txt /path/to/source.txt{}

Ctrl+W (repeat this if once is not enough, but don't Backspace)

$ ln -s ./dir/target.txt {}

Ctrl+{,,,}, ,

$ ln -s {}./dir/target.txt 

Ctrl+Y, Space

$ ln -s /path/to/source.txt. {}/dir/target.txt


  • Based on your answer and the link you provide, I've just learned a whole heap more that I didn't know about bash :) Where does one find these gems? – Madivad Mar 31 '16 at 2:19
  • Easier way to get to before the first path: ctrl-a (start of line), ctrl-right or alt-f twice (forward word). – Peter Cordes Jan 10 '20 at 19:59

I think this can be done using bang commands:

!:0 !:2 !:1

!:0 word designator 0, the zeroth word.
!:n The nth word.

man bash

Word designators, section.

  • Only giving a code snippet is not enough without explanation. – peterh - Reinstate Monica Mar 1 '15 at 23:08
  • I type !:0 !:2 !:1 after /path/to/source.txt, but nothing happens. Obviously, I don't want to execute the incorrect command line. – Vi. Mar 2 '15 at 0:20
  • Word Designators Word designators are used to select desired words from the event. -> Events? Is it that annoying (bash: !": event not found) thing that gets into my way and drops my command line when I forgot to escape !? – Vi. Mar 2 '15 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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