You can use the environment variable CDPATH
for this. From the Bash man page:
CDPATH
The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. A sample value is ".:~:/usr".
In your case, you can set
export CDPATH=.:/user/something/somefolders
in ~/.bashrc
, and then typing cd somewhere
would take you to /user/something/somefolders/somewhere
(assuming there's no directory named somewhere
within the current directory).
Alternatively, if you don't want to refer to the folder somewhere
by its real name, you could create a hidden directory that contains a symbolic link to /user/something/somefolders/somewhere
with the name you want to use. It could also contain links to any other directories you frequently visit. Then set CDPATH
to include the path to that hidden directory. Although note that with this method, if you cd somewhere
and then cd ..
, you'll wind up in the hidden directory. That may or may not be an issue for you.
1How about a directory in the root with a short name, e.g.
/sl
and create shortcuts in there? (ieln -s /long/path/to/some/other/folder /sl/shortcut
? No clutter in the root, plus a visual reminder that your prompt's path is a symlink. – RolfBly – 2016-11-13T19:26:11.723nice one John ! – Gob00st – 2012-10-03T14:54:01.127
it's supposed to be
ln -s /long/path/to/some/other/folder /shortcut
when I did it the other way around it created the shortcut in the place I wanted to create the link to. I submitted an edit to make it updated. – Elias – 2013-08-02T16:38:21.690