Name

pushd

Synopsis

    pushd [options] name
    pushd [options] +n
    pushd

The first form changes the working directory to name and adds it to the directory stack. The second form rotates the nth entry to the beginning, making it the working directory. (Entry numbers begin at zero.) With no arguments, pushd switches the first two entries and changes to the new current directory.

The -l, -n, and -v options behave the same as in popd. See also dirs and popd.

Examples

% dirs
    /home/bob /usr
    % pushd /etc           
                     Add /etc to directory stack
    /etc /home/bob /usr
    % pushd +2             
                     Switch to third directory
    /usr /etc /home/bob
    % pushd                
                     Switch top two directories
    /etc /usr /home/bob
    % popd                 
                     Discard current entry; go to next
    /usr /home/bob

Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.