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


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s