Category Archives: linux

bash alias to change working directory

I recently wanted to make a handy bash alias to change into a directory. Specifically I wanted to access the local /scratch directories of our HPC cluster nodes, which are mounted via autofs on the mother node.

However,bashaliasWell, one can, but it does not work as expected since it does not affect the executing bash.

This problem can be solved  by declaring a bash function (put it in .bashrc or .alias for example). The following code works with the SGE queueing system. From the jobid as argument it extracts all necessary information and finally executes a  change-dir command.

check the gist for the code snippet

If you want to adapt it to your local SGE environment, you would at least need to adjust the hostname (.ibp.cz) and the path to the mounted scratch directories.
The function is executed in the terminal with the jobid as argument as follows:

scrdir 12345

Hope it helps someone.

Share