Linux Instructions pushd quickly switch directories

Source: Internet
Author: User

directive: pushd
Switch between different directories

In the command-line mode, when you need to switch between different directories to find the constant input directory is very troublesome, this time need to use the PUSHD function

pushd working principle:
PUSHD pushes the specified directory into the directory stack maintained by the current shell, enabling you to switch between multiple different paths.

Ps: By default, the PUSHD function may not be included in your Linux, but it exists in red Hat and red hat-powered systems.

Grammar:
# pushd [-n] [+n |-n | dir]

Parameters:
-N: Only add directories to the directory stack, do not switch directories +n: Move the nth directory to the top of the stack (+ indicates the number starting from left or top (top of the stack), the number starts from 0, the top of the stack is +0)-N: Moves the nth directory to the top of the stack (-Indicates the number starts from right or bottom (bottom), number 0, Bottom representation is -0) dir: Specifies the directory to be added to the directory stack and switch to that directory at the same time

Ps:
1, without parameters when the PUSHD command will exchange the top two directories of the directory stack (equivalent to CD-)
2. If you do not specify a directory name when adding a directory, the current working directory will be placed at the top of the directory stack
3, if the directory is not specified when the directory stack location, will be placed in the top of the directory stack
4, the leftmost or above represents the top of the stack, the right or the bottom side represents the bottom of the stack
5, directory stack No. 0 directory (that is, the top directory), is always the current directory
6. The last directory to be put in the heap at the top of the heap
7, when the directory stack is empty, the stack bottom of the directory stack is to execute the pushd command when the working directory
8, when adding pushd and a pathname, will automatically generate a stack, the content is added to the directory name and the current working directory name


Example
There are now three directories that require frequent switching:/doiido/boy:/home/user:/etc/sshd

1: First put three directories into the pushd stack
# Pushd/doiido/boy
/doiido/boy ~
# Pushd/home/user
/home/user/doiido/boy ~
# PUSHD/ETC/SSH
/etc/ssh/home/user/doiido/boy ~


2: View the contents of the stack
The dirs command is to view the contents of the directory stack
# dirs-v
0/etc/ssh
1/home/user
2/doiido/boy
3 ~


3: Toggle
3.1: Switch between/ETC/SSH and/home/user
# pushd

3.2: Switch to/doiido/boy directory
# pushd +2

4: Empty
# dirs-c


Other:
1. If you need to remove a directory from the directory stack, use POPD. For details, see popd use method

2. If you want to view a list of directories in the directory stack, use dirs. For details, see dirs use method



Linux Instructions pushd quickly switch directories

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.