logoalt Hacker News

GNOMESyesterday at 7:45 PM4 repliesview on HN

Simple trick I use almost daily for navigating backwards to an exact directory:

https://gist.github.com/GNOMES/6bf65926648e260d8023aebb9ede9...

I use this often instead of chaining together multiple '../..'.

Also nice for when I use Zoxide to CD into a deep nested directory. I quickly found out unless you manually CD each hop, the different parent directories aren't added to your Zoxide DB. (I have come across snippits to recursively CD into all directories in a path to "prepopulate" Zoxide).

I made this to jump directly from say `/foo/bar/batz/abc/123` to `/foo/bar/batz`.


Replies

zh3today at 8:00 AM

Somewhat along the same lines, as I regularly SSH to other hosts with the same network filesystem mounts, 'scd' starts an SSH session on a remote host in the same directory.

  #!/bin/bash
  # SSH to remote system and change into same (current) directory
  DIR=$(pwd)
  ssh -t $1 "cd $DIR; bash -l -i"
show 1 reply
urxvtcdtoday at 8:24 AM

For fish shell users, you get chronological directory traversal with Alt-Left Arrow and Alt-Right Arrow.

exdeejay_yesterday at 8:10 PM

This is a neat and useful trick, and I will be borrowing it. Thanks!

RhysUyesterday at 11:10 PM

Abbreviate moving up in the directory hierarchy:

  alias ..="cd .."
  alias ...="cd ../.."
  alias ....="cd ../../.."
Just keep typing period and hitting enter until you get where you want according to your prompt. I haven't found much use for more than four periods. One period would be well-defined but useless.