How to use Linux command switching directory _linux shell

Source: Internet
Author: User

1.CD-The function is to quickly switch to the previous directory , as follows:

Copy Code code as follows:

amosli@amosli-pc:~$ CD learn/fd/
amosli@amosli-pc:~/learn/fd$ CD-
/home/amosli

2.dirs: Display the directory stack, listing the list of directories saved in the current stack

Copy Code code as follows:

amosli@amosli-pc:~/learn/fd$ dirs
~/learn/fd

Note: the-p parameter of dirs can display the list of directories in the stack in one directory per row
-v argument can be numbered before the table of contents
Note: When-V is not added-P can also be displayed as a table of contents per row

Copy Code code as follows:

amosli@amosli-pc:~/learn/fd$ Dirs-p-V
0 ~/LEARN/FD

The directory into the stack is on top

Introduction to the 3.PUSHD,POPD command

PUSHD: Switches to a directory as a parameter and presses the original directory and current directory into a virtual stack

If you do not specify a parameter, the previous directory is returned and the last two directories in the stack are exchanged

POPD: Removes the most recent directory from the stack

Copy Code code as follows:

amosli@amosli-pc:/$ pushd bin/
/bin/
amosli@amosli-pc:/bin$ pushd/home/amosli/learn/fd/
~/learn/fd/bin/
amosli@amosli-pc:~/learn/fd$ Dirs-p-V
~/learn/fd
/bin
/
amosli@amosli-pc:~/learn/fd$ pushd/home/amosli/develop/
~/develop ~/learn/fd/bin/
amosli@amosli-pc:~/develop$ Dirs-p-V
~/develop
~/learn/fd
/bin
/

The above uses the PUSHD command to push/, bin/,/home/amosli/learn/fd/,/HOME/AMOSLI/DEVELOP/4 directories into the stack, which is the data structure of the LIFO (Lifo,last in first).

So how do I switch directories?

1 if it is directly pushd without parameters, then switch directly to the nearest directory.

Copy Code code as follows:

amosli@amosli-pc:~/develop$ pushd
~/LEARN/FD ~/develop/bin/
amosli@amosli-pc:~/learn/fd$

2) pushd +n

You can also follow the numbers to switch directly to the appropriate directory. For example, switch to/(root directory) as follows:

Copy Code code as follows:

[Code]
amosli@amosli-pc:~/learn/fd$ pushd +3
/~/LEARN/FD ~/develop/bin
amosli@amosli-pc:/$ ls

How do I remove a directory?

1) popd directly remove the nearest directory

Copy Code code as follows:

amosli@amosli-pc:/$ Dirs-p-V
0/
1 ~/learn/fd
2 ~/develop
3/bin
amosli@amosli-pc:/$ popd
~/LEARN/FD ~/develop/bin
amosli@amosli-pc:~/learn/fd$ Dirs-p-V
0 ~/LEARN/FD
1 ~/develop
2/bin

2) popd +n

Just follow the numbers, remove the specified directory

Copy Code code as follows:

amosli@amosli-pc:~/learn/fd$ popd +1
~/learn/fd/bin
amosli@amosli-pc:~/learn/fd$ Dirs-p-V
0 ~/LEARN/FD
1/bin

Related Article

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.