Live data from Hacker News

How to navigate directories faster with Bash (2015)

mhoffman.github.io

31–40 of 179 posts

Re: How to navigate directories faster with Bash (2015)

#31
I independently also have a stack of '...', '....' etc aliases almost exactly the same as this! Extremely useful I reckon!

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.

Re: How to navigate directories faster with Bash (2015)

#34
post #7
post #2

I 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.

More shortcuts like that https://stackoverflow.com/questions/38176514/re-run-previous...

Re: How to navigate directories faster with Bash (2015)

#35
post #7

Earlier 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.

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.

Re: How to navigate directories faster with Bash (2015)

#36
post #14
post #6

Good 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…

Is there a way to tell CTRL-w to break words at / as well as space? I often use it to remove a parameter from a command I've copy-pasted or got from the history, but for the cd use case it removes too much.

Edit: ESC followed by backspace seems to work.

Re: How to navigate directories faster with Bash (2015)

#38
post #2

I 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…

Is !$ the same as $_ ?

Re: How to navigate directories faster with Bash (2015)

#39
Wow I’m just blown away by this.

Really 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)

#40

Earlier 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.

May favorite bash "trick" is:

!-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.

Post reply on HN