bash: cut paste on cmdline

terminalWhile using bash there are many time you may need to copy an argument you have already typed. Instead of typing the argument again you can use the following shortcuts:

Ctrl-w : cut the word before the cursor
Ctrl-u : cut the part of the line before the cursor
Ctrl-y : paste at cursor location

Now if you want to copy the second argument video.mkv at the end in the following line and add .orig:

$ cp video.mkv<Ctrl+w><Ctrl+y><space><Ctrl+y>.orig

In a situation you need to run a command before the current one you already typed, use Ctrl-u to cut the whole line you typed, run the required command and again use Ctrl-y as:

$ vi myfile.c<Ctrl-u> //to cut the whole line
$ dos2unix myfile.c //run the command you missed
$ <Ctrl-y> //copy back the old line

Leave a Reply

Your email address will not be published. Required fields are marked *