Jump to project’s directory using simple bash function

Last Updated at : September 1, 2017 By - Usama Muneer | 1956

    Normally you cd into your html or code directory and then cd into your project’s directory. In this article I’ll explain how a simple bash function can save up your precious time for cd-ing into directories over and over again.

    Let’s straight dive in and open up our bash file. In my case, it’s bash_profile

    Open up your terminal & follow along.

    $ subl ~/.bash_profile


    The function

    function cdhtdocs {
     cd "C:/xampp/htdocs/$1"


    Add into the context

    $ source ~/.bash_profile


    The use-case

    Now lets assume you want to switch to your project’s directory that’s located in “C:/xampp/htdocs/foobar”.

    You’ll have to simply type:

    $ cdhtdocs foobar


    Easy? Isn’t it?


    Final Words

    Bash functions are always helpful if you know the right use-case. If you’re a terminal rookie, then this little trick might come in handy.

    If you’ve any questions, leave us a comment below or ask us on Twitter.

    blog user
    Usama Muneer

    A web enthusiastic, self-motivated & detail-oriented professional Full-Stack Web Developer from Karachi, Pakistan with experience in developing applications using JavaScript, WordPress & Laravel specifically. Loves to write on different web technologies with an equally useful skill to make some sense out of it.

    Related Posts

    How many times do you have to sudo edit your bashrc or bash_profile file for creating new aliases? and then sourcing it every single time?