Say if I need to do this a lot:
cd ../../../../foo/sub1/bar/dest/
cd ../../../../foo2/sub1/bar/dest/
cd ../../../../foo3/sub1/bar/dest/
cd ../../../../foo/sub1/bar/dest/
Is there any faster way to not always typing ../../../../
so many times? Any creative ideas?
The classic way of doing this is setting the
CDPATH
variable. In your case it could be set to.:../../../../
or.:/path/to/the/parent/of/foo
to achieve the desired effect. You can then simply docd foo/sub1/bar/dest
and get to where you want.The advantage of this is that tab completion for
cd
also looks at$CDPATH
and will magically work.You can use autojump which automatically learn from previous cd command and you only need to specify unique string from full path next time. ex.
j foo
,j foo1
,j foo2
You can create shortcuts for these commands by adding aliases into the bash configuration file (~/.bashrc or /etc/bash.bashrc)
Then when you type
cdd
it will execute that command.I recently came across https://github.com/rupa/z, which lets you jump to a recently used directory by regex. So you could do something like:
instead of:
(as long as you have visited that directory before, and nothing more recent / frequently used matches that regex)