9

I constantly need to type:

cd /home/geo/Geant4/geant4.10.00.p02-install/lib/Geant4-10.0.2

How do I create an alias to that directory, so I could just type:

cd $geant (or any other word I decide to create as the alias name)

It would also help me whenever I need to use cmake because I could use $geant as well in the middle of a cmake option.

Thanks.

Geo
  • 1,255
  • 1
  • 9
  • 16
  • uhh sorry. I'm new to ubuntu and those stuff and I didnt know that it was basically the same question – Geo Jun 23 '14 at 01:20
  • No problem! askubuntu does this automatically when I mark a question as duplicate to let you know where you find your answer. That's the beauty of it. – mniess Jun 24 '14 at 06:54

2 Answers2

9

Open your $HOME/.bashrc and append:

export GEANT=/home/geo/Geant4/geant4.10.00.p02-install/lib/Geant4-10.0.2

then run source ~/.bashrc and now you schould be able to use it like this:

cd $GEANT
TuKsn
  • 4,370
  • 2
  • 26
  • 43
  • thank you sir. i have been trying with the alias command, but seems they are only to command – Geo Jun 22 '14 at 21:24
  • You are welcome!. I described the way how you can create your own environment variable (more info: http://askubuntu.com/questions/730/how-do-i-set-environment-variables). Alias do not work in this case (as far as I know). – TuKsn Jun 22 '14 at 21:34
1

Just create a link in nautilus, and treat it as a normal folder. Terminal will go straight to it.

Tim
  • 32,861
  • 27
  • 118
  • 178
  • actually I dont mind the "cd" part. i care more about the cmake. i always need to do cmake -dGeant4_DIR=/home/geo/Geant4/geant4.10.00.p02-install/lib/Geant4-10.0.2 and thats a long command which i need to keep looking the full directory everytime i run the program. I'd rather type cmake -DGeant_DIR=$geant. – Geo Jun 22 '14 at 21:05
  • I think that will work. – Tim Jun 22 '14 at 21:05
  • tried it using cmake. it gave errors when configuring =\ – Geo Jun 22 '14 at 21:12
  • @Geo Can you show the errors to us? – Tim Jun 23 '14 at 08:40
  • sure. After installing Geant4, tried to run an example (B3) with the /home/geo/geant being a link to that big directory i need to use

    heres the output: http://imageshack.com/a/img855/4199/dd5n.png

    – Geo Jun 23 '14 at 15:28
  • Tuknutx has the right idea, use that. Sorry mine was wrong... – Tim Jun 23 '14 at 15:30
  • its cool =) your mode works with a "cd" command, but some programs (or at least geant4) had a problem reading that as a link – Geo Jun 23 '14 at 15:34
  • Yeah :) An I learnt that I could use them in terminal! :P – Tim Jun 23 '14 at 15:34