Another thing that I've found surprisingly invaluable is an alias (i went for 'ccd') that figures out (via python, so a bit slower on the 1st run) what part of the argument is a valid directory and then cd's you there. It's very handy indeed when working with file paths all the time (a film-vfx-on-Linux use-case) otherwise you end up using backspace to delete the file part constantly! In fact, about that: hitting Esc-Backspace in sequence, should delete back to the next word separator instead of one char at a time.
How to navigate directories faster with Bash (2015)
31–40 of 179 posts
Re: How to navigate directories faster with Bash (2015)
#32I vote for creating a « mkcd » alias !!
# create a directory in the current directory and cd to it
function mkcd() { mkdir -p "$@" && eval cd "\"\$$#\""; }Re: How to navigate directories faster with Bash (2015)
#33Re: How to navigate directories faster with Bash (2015)
#34I 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…
Typing Esc then . does the trick too.
Re: How to navigate directories faster with Bash (2015)
#35Earlier quoted context omitted.
Typing Esc then . does the trick too.
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.
Re: How to navigate directories faster with Bash (2015)
#36Good selection of tips, like Normille I didn't know $! even though I have read Bash's man page through more than once. Note that many of these are not just for Bash. pushd/popd is near universal among shells and CDPATH is standard among SYSV shells. The idea of a shortcut for cd .. and its repetitions is good, but I'd prefer alias p='cd ..', pp='cd ../..' and so on, since I balk at the idea of having to distinguish,…
I'm an old-timer so was introduced to Unix before bash was ubiquitous. Actually it was csh/tcsh which later introduced me to "interactive" command history/editing. With interactive command history/editing, the old tricks to avoid excessive typing became less essential. But I still use some of the old techniques as they continue to save time/typing - particular "$!". And even though I've reduced my reliance on aliases…
Edit: ESC followed by backspace seems to work.
Re: How to navigate directories faster with Bash (2015)
#37Re: How to navigate directories faster with Bash (2015)
#38I 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…
Re: How to navigate directories faster with Bash (2015)
#39Really cool trick to navigate directories fast I’m definitely going to add this to my .zshrc
Honestly commandline has made so many things easier for me that I don’t even use regular apps besides my browser for browsing web anyhow using commandline has really made me productive
And I always look for automating or making the workflow better
Anyways great post thanks for sharing:)
Re: How to navigate directories faster with Bash (2015)
#40Earlier 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.
Cool one. "Ctrl + R" also does the same thing to search through past commands and then "Tab" to select the command you are looking for.
!-1:gs/hello/world
which runs the last command with all instances of hello replaced by world. !-1 can be any so called event designator, for instance !n to refer to any specific line number from history or !string for last command containing a particular string.
Seriously people, read the man page for bash. Your shell has so many cool features.