Did you know how to replace via the ^ command with bash?
Hello All!
At first, I want to ask one question about using the popular bash commandline interpreter. Did you know about the ^ command?
If yes, you are a really well expierenced bash-user. If not, you won't loose anything in reading this blog entry. The command ^ is used to substitude some text, typed the last time before you hit the enter key.
One example of how to use it, surely makes the usage clear:
Let's assume you have a directory called "~/temp". And because of your writing speed, you make a typing mistake like that:
Now you can use the ^ command:
Did you see the what it does?
It replaces all occurences of the first part between the two carets (^) with the part between the last caret and EOL.
This can be sometimes a powerful trick to navigate through directories.
For instance, if you have child directories, whose names aren't much different from their parents one, such in this case:
Seems powerful, doesn't it?
I hope I could give you a short introduction into this advanced bash command. If you have any questions, improvements or anything else, feel free to post comments.
Have a nice day with it!
At first, I want to ask one question about using the popular bash commandline interpreter. Did you know about the ^ command?
If yes, you are a really well expierenced bash-user. If not, you won't loose anything in reading this blog entry. The command ^ is used to substitude some text, typed the last time before you hit the enter key.
One example of how to use it, surely makes the usage clear:
Let's assume you have a directory called "~/temp". And because of your writing speed, you make a typing mistake like that:
Code:
user@machine ~/temp $ cd temo -bash: cd: temo: No such file or directory
Code:
user@machine ~ $ ^o^p cd temp user@machine ~/temp $
It replaces all occurences of the first part between the two carets (^) with the part between the last caret and EOL.
This can be sometimes a powerful trick to navigate through directories.
For instance, if you have child directories, whose names aren't much different from their parents one, such in this case:
Code:
user@machine ~/temp $ cd temp1 user@machine ~/temp/temp1 $ ^1^2 cd temp2 user@machine ~/temp/temp1/temp2 $ ^2^3 cd temp3 user@machine ~/temp/temp1/temp2/temp3 $ ^3^4 cd temp4 user@machine ~/temp/temp1/temp2/temp3/temp4 $
I hope I could give you a short introduction into this advanced bash command. If you have any questions, improvements or anything else, feel free to post comments.
Have a nice day with it!
Total Comments 2
Comments
-
didn't know that, interesting. but imo inCode:
cd tmo
I'm not lazy in fact and I don't like to get used to some hacks like that.Posted 03-12-2010 at 10:51 AM by Web31337
Updated 03-12-2010 at 10:53 AM by Web31337 -
No, I did not know that. Freaky!
Posted 03-12-2010 at 05:21 PM by CoderMan