Live data from Hacker News

How to navigate directories faster with Bash (2015)

mhoffman.github.io

11–20 of 179 posts

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

#11
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…

I got stuck with exactly that use case today and trying to figure out how I can enter directly to my dir without typing it again. Bash is no so neat at completions like Fish for example. However !$ does the thing and keeps my fingers healthy.

That's great set of tips BTW.

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

#12
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.

I didn't know this. Really neat!

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

#13
post #5

I use `z` as a less manual way to search common directories instead of changing $CDPATH. It's based on 'frecency'. https://github.com/rupa/z

After trying such history-based automatic tools I found they lacked predictability for me.

So the very small 50 LOC kd was born:

    kd # jumps to project top level (based on .git/Gemfile)
    kd foobar "$PWD" # saves an entry named foobar pointing to $PWD
    kd foo # jumps to foobar
    cp qux $(kd foo) # expands to foobar's value
I should probably make it expand to absolute paths so that I could change "$PWD" to .

https://github.com/lloeki/dotfiles/blob/master/shell/kd

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

#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, I'm so used to jumping between directories that "pd" (pushd) and "nd" (pushd +1) are some of the few I continue to find myself installing.

The other shell techniques (strictly speaking editing features) that I was surprised to find are generally less used these days are the shortcuts like CTRL-w to delete the word to the left of the cursor or CTRL-a, CTRL-e to navigate to the start and end of the current line.

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

#15
post #5

I use `z` as a less manual way to search common directories instead of changing $CDPATH. It's based on 'frecency'. https://github.com/rupa/z

I use `autojump` (aliased as `j`), which sounds quite similar as it also records your most frequently visited directories. It's as simple as entering `j down` to enter /some/path/to/MyDownloadFolder.

For exploring massive file trees, a terminal file manager that allows you to preview the contents of subdirectories without entering them is huge time saver. I use `lf`.

https://github.com/wting/autojump

https://github.com/gokcehan/lf

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

#17
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.

Wow amazing! Thanks :)

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

#18
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.

That's just magical
Post reply on HN