come back to the own directory that just past   in linux

Posted on 2007-10-21
Last Modified: 2013-12-16

I stay in the direc tory above then i go to   cd /home

How can i come back to  /var/www/vhosts/

I can not use arrow up and down be cause I goto cd/var then d www then cd vhosts  
Question by:teera
    LVL 9

    Assisted Solution

    you can always set the path as a variable, and use it in your shell session


    # longpath="/var/www/vhosts/"
    # cd /home
    # ls
    # cd $longpath
    LVL 40

    Assisted Solution


    One way of doing it is as recommended by ghostdog74, by setting env variable then using it whenever you want.

    Another way is to use pushd / popd commands. For more info, please see:

    LVL 19

    Accepted Solution

    put these functions on your ~/.bashrc so they are in your environment when you open the terminal:

    function dmark {

    function djump {
    cd $DMARK

    now you can go to /var/www/vhosts/
    and execute:
    #change to home
    cd ~
    # see? you are in home now:
    # change even to root directory
    cd /
    # now get back to the beginning:
    # see? you are just where you dmark-ed the directory

    you can name these two commands as you please. you can also add more functionality like push and pop multiple times, but this is the answer to what you asked.

    LVL 48

    Assisted Solution

    It's also useful to know that

    cd -

    Will cd you to the last directory you were in, which in this instance won't help you directly, but it still useful to know.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This document is written for Red Hat Enterprise Linux AS release 4 and ORACLE 10g.  Earlier releases can be installed using this document as well however there are some additional steps for packages to be installed see Metalink. Disclaimer: I hav…
    You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now