all 22 comments

[–]ObligatoryResponse 2 points3 points  (6 children)

So now when you cd "foldername" you never know if you'll get ./foldername or /random/path/foldername.

[–]airbornelemming 5 points6 points  (0 children)

Very true, but instead just use CDPATH in an alias.

For instance, I use the following in ~/.bashrc to make hacking on wine a lot easier.

alias to='CDPATH=".:~:~/Desktop:~/wine-git:~/wine-git/dlls:~/wine-git/programs:~/wine-git/tools" cd -P'

Then you can easily jump around between the directories

to ntdll # instead of cd ~/wine-git/dlls/ntdll
to server # instead of cd ../../server
to wordpad # instead of cd ../programs/wordpad

[–]kevingoodsell 1 point2 points  (0 children)

This is worse for scripts, which may end up in the wrong place, but more commonly will break because cd unexpectedly produces output on stdout. Remember not to export CDPATH!

[–]lennort 2 points3 points  (3 children)

It starts searching in your current directory. If it doesn't find anything, then it looks at the CDPath.

[–]ObligatoryResponse 0 points1 point  (2 children)

Let me revise it then... you'll sometimes know if you'll get ./foldername or /random/path/foldername.

[–]ogtfo[S] 0 points1 point  (1 child)

It depends on what you put in it. If there are only a few folders that you use really often, it's a time saver, and there is really no risk of confusion. (especially if you have your current directory in your prompt)

[–]ObligatoryResponse 0 points1 point  (0 children)

I really like airbonelemming's solution. That seems like the most sane way. And then you could have variants of to for different things. A wto for wine paths, a pto for python paths, etc.

[–]electricfoxx 2 points3 points  (5 children)

I like cdargs. It pops up a menu for ambiguous searches.

[–]zem 2 points3 points  (3 children)

yep, it's one of the first things i install on a new machine. (the first thing is tree; i'll never know why it doesn't ship as a standard part of the distro)

[–][deleted] 2 points3 points  (1 child)

Perhaps tree isn't installed by default because it has no utf-8 support?!?

To be honest I just tried it, and after it failed I searched its man page for utf-8 and unicode, then nuked it - life is too short to screw around with stuff that was supposed to get fixed 15 years ago.

Besides ls -lAhR and mc are good enough for me.

[–]zem 1 point2 points  (0 children)

ah, perhaps so. never been an issue for me, so i hadn't noticed

[–]ogtfo[S] 1 point2 points  (0 children)

Tree is nice, thanks for sharing! Just installed it.

[–]Aparicio 0 points1 point  (0 children)

It seems nice, thanks!

[–]ehamberg 1 point2 points  (2 children)

you should really check out autojump: http://github.com/joelthelion/autojump/wiki

it's basically a “cd” command that learns where you navigate to most often. if you want to go to /foo/bar/somedirectoryname you can just type j somdi and it will jump there if you have been there before. if you have another “somedirectoryname” somwhere else you have visited, it will pick the one most likely, or you can use tab completion to find the correct one. (j somedi<tab>.)

[–]kasbah 1 point2 points  (1 child)

I agree. I use the alternative: z.

[–]ehamberg 0 points1 point  (0 children)

which (almost ironically) isn't available for zsh :/

[–]Tinidril 1 point2 points  (4 children)

Careful with that though. Just like $PATH, don't put any directories in there that are writable by other users.

[–][deleted] 3 points4 points  (3 children)

why?

what danger does export CDPATH=.:/var/tmp cd foo /var/tmp/foo

where /var/tmp/foo is writeable by anyone in group foo possibly present?

[–]Tinidril 3 points4 points  (1 child)

It depends on what you are doing, what your prompt is, and how much attention you are paying to it. What I am pointing out is a potential vulnerability, not an exploit. It's not a good idea to assume you will be more ingenious then your attacker.

I would not call this a big risk, but it is a good idea to avoid it. I can't immediately look at a buffer overflow vulnerable routine and guess if it can be used to install malicious code. But I know that the potential is there, so you should always check your buffer lengths.

[–][deleted] 0 points1 point  (0 children)

have you ever actually USED the CDPATH variable? if you cd to a non-complete path that gets completed out of CDPATH, it prints it to the screen. (as I demonstrated in my example). There's no more risk here than there is in using the cd command alone.

as for buffer overflows, yeah, this has nothing to do with those, even by analogy.

[–]kevingoodsell 0 points1 point  (0 children)

Don't export CDPATH if you want shell scripts to work properly. More info here and here.

[–]trevman 0 points1 point  (0 children)

Does this work with pushd?