Change the first word of the previous command

bashcommand linehistory

For example I enter

cat /very/long/path/textfile

and right after that I decide to give the next command

rm /very/long/path/textfile

So, my question is: What is the easiest/fastest way to replace the first word of a previous command? (without arrow keys or copy-paste)

It should work for any command (cat, rm and textfile are just for this example, it doesn't have to be those)

Best Answer

Assuming that you’re running a shell with a standard history mechanism (e.g., bash, C shell, …), type the new command (e.g., rm) followed by !*.  Type man bash, man csh, or whatever is appropriate for you, to see more details (and there are lots of them).

Related Question