Live data from Hacker News

How to navigate directories faster with Bash (2015)

mhoffman.github.io

61–70 of 179 posts

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

#61

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

No need for stacks of `..`. Use this instead:

function up() { for i in $(seq 1 $1); do cd ..; done }

# usage:

up # goes up 1 directory

up 2 # goes up 2 directories

up 42 # goes up 42 directories

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

#62
post #3

I vote for creating a « mkcd » alias !!

Here's my answer to that, an 'nd' (newdir?) alias that calls this python script:

https://github.com/danwills/shell-scripts/blob/bb989985d270c...

This makes all directories with names provided by args, including spaces and multiple levels (slashes) at once. It then enters the resulting directory as well (when aliased including 'cd' as advised in the comment).

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

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

[deleted]

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

#64

Here is one additional bookmark solution [1]: export CDPATH=.:~/.marks/ function mark { ln -sr "$(pwd)" ~/.marks/"$1" } mark @name # create a bookmark cd @name # jump to bookmark cd @ # list bookmarks cd @n # auto-complete cd @name/ # can access sub-directories within bookmarks Works best when bookmarks are prefixed by "@" or other special symbol. Additional advantage is that you can use the same function `cd` to nav…

This is AWESOME. Thank you.

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

#66
post #65

I haven’t tested this exact scenario but I like doing something like this when needed mkdir -p path/to/{one,two,three}/done To create: * path/to/one/done * path/to/two/done * path/to/three/done

Particularly helpful for quickly appending something to a file name

    mv something{,.old}

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

#67
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 have an "mkcd" function in my startup files:

mkcd() { mkdir -vp "$1" && cd "$1"; }

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

#69
post #67
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 have an "mkcd" function in my startup files: mkcd() { mkdir -vp "$1" && cd "$1"; }

+1, I do the same.

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

#70
post #65

I haven’t tested this exact scenario but I like doing something like this when needed mkdir -p path/to/{one,two,three}/done To create: * path/to/one/done * path/to/two/done * path/to/three/done

Shell alternation globs do ranges too, so be careful :)

  echo -e {A..Z}{a..z}{0..9}/{A..Z}{a..z}{0..9}"\n"|wc -l
  45697601
Runs for a bit too.
Post reply on HN