I have a few functions in my bashrc for fast directory navigation. up - cd .. # times upto - find dir in the current path above you and cd to it down - find dir in the current tree below you including inside any number of subdirectories and cd to it https://github.com/robmccoll/dotfiles/blob/master/bashrc#L15...
How to navigate directories faster with Bash (2015)
91–100 of 179 posts
Re: How to navigate directories faster with Bash (2015)
#92I upvoted for this alone: Another neat short hand is !$ which is an alias for the last argument of the previous command. This can be handy if one creates a new directory and wants to change into it without typing the the directory again. So commands would be mkdir -p make/new/directory cd !$ You've no idea how many years I've been thinking "This is Linux fer gawd's sake. Surely there must be some easy way to make a n…
escpae-dot (.) also works for this: "It also works to use !$ instead of escape-dot, but that is slightly harder to type, so I don’t use that anymore." Wrote about it here: https://henrikwarne.com/2018/08/11/my-favorite-command-line-...
Re: How to navigate directories faster with Bash (2015)
#93Earlier quoted context omitted.
I have an "mkcd" function in my startup files: mkcd() { mkdir -vp "$1" && cd "$1"; }
Wait, now I'm confused. I have: mkcd() { mkdir -p "$@" && cd "$_"; } Can someone please detail the differences between $! and $_? (Apologies if I'm missing something obvious)
$ echo "test" > /dev/null && echo !$
/dev/null
$ echo "test" > /dev/null && echo $_
testRe: How to navigate directories faster with Bash (2015)
#94Earlier quoted context omitted.
Alt + . does the same thing as well, with the added advantage that you can keep pressing alt and then hit . several times to go through all the "last arguments" in your history one by one. Further, holding Alt followed by numeric argument followed by dot, gives you an argument at a specific position. For example, Alt + 1, Alt + . copies the first argument.
[ESC + .] and [ALT + .] are most definitely news ones for me. Thank you. Always learn something new here!
Re: How to navigate directories faster with Bash (2015)
#95Earlier quoted context omitted.
escpae-dot (.) also works for this: "It also works to use !$ instead of escape-dot, but that is slightly harder to type, so I don’t use that anymore." Wrote about it here: https://henrikwarne.com/2018/08/11/my-favorite-command-line-...
Which you can type as ALT-.
"Insert last argument to the previous command (the last word of the previous history entry). With a numeric argument, behave exactly like yank-nth-arg. Successive calls to yank-last-arg move back through the history list, inserting the last word (or the word specified by the argument to the first call) of each line in turn."
https://tiswww.case.edu/php/chet/readline/readline.html#IDX9...
Its sibling is `yank-nth-arg`, bound to M-C-y. So if you want the 2nd argument from the last command, you can press M-1 followed by M-C-y (yeah, arguments are indexed from 0)...
https://tiswww.case.edu/php/chet/readline/readline.html#IDX9...
Re: How to navigate directories faster with Bash (2015)
#96Earlier quoted context omitted.
Alt + . does the same thing as well, with the added advantage that you can keep pressing alt and then hit . several times to go through all the "last arguments" in your history one by one. Further, holding Alt followed by numeric argument followed by dot, gives you an argument at a specific position. For example, Alt + 1, Alt + . copies the first argument.
[ESC + .] and [ALT + .] are most definitely news ones for me. Thank you. Always learn something new here!
Re: How to navigate directories faster with Bash (2015)
#97Earlier quoted context omitted.
I have an "mkcd" function in my startup files: mkcd() { mkdir -vp "$1" && cd "$1"; }
Wait, now I'm confused. I have: mkcd() { mkdir -p "$@" && cd "$_"; } Can someone please detail the differences between $! and $_? (Apologies if I'm missing something obvious)
I would not that !$ is a bash-ism, whereas $_ works at least on zsh and ksh as well as bash.
Re: How to navigate directories faster with Bash (2015)
#98There're only few directories I need to change to daily. So when I have to visit them, I need to type only `z first_two_characters_of_the_directory_name`
Re: How to navigate directories faster with Bash (2015)
#99Earlier quoted context omitted.
https://stackoverflow.com/questions/41385015/what-is-bang-do...
Looks like !$ is a readline feature and $_ is a shell variable?
And !$ is documented here: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash....