Can I make the value of . to be a different directory from the current directory?


I'm learning Java. In the directory of my program, I have two sub-directories, src and bin. Every time I have to compile my code, I enter src to call javac, because of the path of the Java classes imported in the source file, and I specify the destination for storing the .class files to be ../bin. When I run my code, I enter ../bin, to call java.

When I need to modify my code and recompile, I enter ../src again for running javac. Then I need to enter ../bin to run my program. Constantly changing my code leads to constantly switching my current directory between src and bin.


  • I wonder if the organization of my program files (source and executables) is incorrect, for example, shall I put all source and executable files under the same directory, so that no need to switch?
  • However that seems unwise, since it will mix source and executables in the same directory?

closed as unclear what you're asking by Gilles, Braiam, slm Oct 8 '14 at 23:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I just figure out that I can go under the parent of src and bin, and specify src to javac -cp and bin to java -cp. But adding bin to java -cp means java -cp bin bin.mycode? I didn't have package bin.mycode in my source, but just package mycode. – Tim Oct 8 '14 at 12:51
  • have you consider 1) use of cd - when switching, 2) have two tty (if it is possible) ? – Archemar Oct 8 '14 at 12:59
  • @jimmij: I see. – Tim Oct 8 '14 at 13:13
  • I’m not sure what you’re really asking, but maybe these will help: (1) In bash, at least, if you set CDPATH=$HOME (or add the value of $HOME, colon-delimited, to your current value of CDPATH), then you can say cd bin from anywhere in the file system and it will take you to ~/bin (i.e., you don’t need to type ../). And, of course, cd src will work the same way. (2) If, in the src directory, you type ln -s ../bin b, then you can type cd b (from the src directory) to go to ~/bin. (And, of course, vice versa.) (3) You can define aliases for cd ~/bin and cd ~/src. – G-Man Oct 8 '14 at 18:01
  • (4) In bash, at least, if you say shopt -s autocd, then you can simply type the name of a directory, and (if there isn’t a command by the same name) the shell will go to that directory. In conjunction with the CDPATH trick, this would mean that you could type merely bin and you would go to ~/bin. Of course, this isn’t really any more powerful than defining aliases. (5) I almost overlooked it, so, in case you did, too: @Archemar suggested having two windows (ttys), keeping one in each directory. (There are many keyboard shortcuts for switching between windows.) – G-Man Oct 8 '14 at 18:03

. is not a variable with a value. It is a (special) file in the filesystem. You cannot change it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.