Linux Command CD pushd popd

Source: Internet
Author: User

Working in a LINUX multi-directory command prompt is a pain point, but the following tips on using Linux CD commands and pushd to switch directories help you save time and effort.

In the Linux Command Prompt, run the Linux CD command to change the current directory. This is a basic usage of the Linux CD command:

Change your root path, type the CD command, and press Enter.

Enter a sub-directory, enter the CD command, space, then the sub-path name (for example, the CD command documents), and then press Enter.

Enter the upper-level directory of the current directory, type the CD command, space, two points, and then press Enter.

Enter a specific directory, enter the CD command, space, path name (such as CD command/usr/local/LIB), and then press Enter.

To confirm your directory, type PWD and press Enter. You will see the name of your current directory.

Use pushd to switch between different directories.

In command line mode, when you work in different directories, you will find that you have a lot of time wasted on Repeated input. If these directories are not in the same root directory, you have to enter the complete path name during conversion, which is hard to bear. However, you can use one or two of the following steps to avoid unnecessary input: Use the history records in the command line interpreter, or use the command line function pushd.

The benefit of using the command line interpreter is that you only need to press a few keys. Use the up arrow in the command line to find the commands you have used until you find them and press Enter. If the two directories you switch to are very close to the sub-directory structure of the entire drive, the history record in the interpreter may be your best choice.

However, if you convert two completely different paths, you may want to use the pushd function to create a directory stack (a list in memory ).

Note: by default, pushd functions may not be included in your Linux system, but they are included in Red Hat and Red Hat-driven systems. If you do not have pushd functions in your system, you can download related function tools from the ibiblio.org website.

Here we will talk about how to use pushd. Suppose you are working in the/usr/share/fonts directory. You need to make some changes to/usr/share/fonts, And you will frequently switch between the two directories. Start to switch to another directory with the pushd function in one directory. In our example, start with/usr/share/fonts, type pushd/opt/wonderword/fonts, and then press Enter. Now you will see the content in the stack in the next line:/opt/wonderword/fonts/usr/share/fonts.

As you can see, when you type pushd and a path name, a stack is automatically generated with the directory name you typed and the directory name you are currently working on. In our example, the path (/opt/wonderword/fonts) You typed is at the top of the stack.

Quickly return to the upper-level directory. You can directly type pushd. If you do not follow the path name, you will return to the upper-level directory of the previous directory in the stack.

If you need to delete a directory from the stack, type popd, name the directory, and press Enter. To view the directory list in the stack, type dirs and press Enter. The popd and dirs commands are also part of common functions.

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.