Guidelines for using Linux switching paths

Source: Internet
Author: User
Tags ssh

As long as you play Linux command line, switch directories that is a piece of cake, the Direct CD command is done, but in addition to simple CD command, there are many other commands to make your operation more convenient and quick.

Suppose a situation, a file a stored in the tenth level directory ten, after arduous difficulty entered the ten, the result accidentally typed a CD command, looking at the cursor in the root directory flashing, is not very helpless? Do you have to hit a bunch of paths again and go back to the ten directory?

Needless to bother, enter "CD-" and see if it's back to the path just now?

Note: "CD-" will be able to complete the current directory and the previous directory of the Switch between

Another convenient path to switch the command is pushd, you can complete a number of different paths between the switch.

If I want to switch between/usr and/etc/ssh and/etc/rc.d and the current path, you can enter at the command line:

Pushd/usr

/usr ~

Pushd/etc/ssh

/ETC/SSH/USR ~

Pushd/etc/rc.d

/ETC/RC.D/ETC/SSH/USR ~

PUSHD will automatically add the current path to the switchable path. To perform dirs, you can see four paths displayed:

Dirs

/ETC/RC.D/ETC/SSH/USR ~

Enter PUSHD to switch between the first two paths.

If you want to switch to the last (stack bottom) path, pushd +2.

pushd

/ETC/SSH/ETC/RC.D/USR ~

pushd

/ETC/RC.D/ETC/SSH/USR ~

pushd +2

/usr ~/etc/rc.d/etc/ssh

If you want to empty these paths, execute dirs-c.

Dirs-c

Dirs

/usr

If you need to remove a directory from the stack, type popd, then the directory name, and then press ENTER

Working in a Linux multiple directory command prompt is a pain, but the following tips for using CDs and PUSHD to switch directories can help you save time and effort.

In the Linux command prompt, use the CD command to change the current directory. Here are some basic uses of the CD command:

Change your root path, type the CD, and press ENTER.

Enter a subdirectory, type a CD, a space, then a subpath (for example, CD Documents), and then press ENTER.

Go to the top level of the current directory, type a CD, a space, two points, and then press ENTER.

Enter a specific directory, type a CD, a space, a path name (for example, Cd/usr/local/lib), and then press ENTER.

To determine your directory, you can type pwd, press ENTER, and you will see the name of your current directory.

Switch between different directories with PUSHD implementation.

In command line mode, when you work in different directories, you will find that you have a lot of time to waste on repetitive input. If these directories are not in the same root directory, you will have to enter the full pathname in the conversion, which is hard to bear. But you can use one or two of the following steps to avoid all the extra input: Using the history of a command-line interpreter, or pushd with a command-line function.

The advantage of using historical records in the command-line interpreter is that you simply press a few keys. Use the UP arrow on the command line to find the command you have used until you find it and press ENTER. If the two directories you switch are very close to the subdirectory structure of the entire drive, the history in the interpreter may be your best bet.

However, if you are converting between two distinct paths, you may well want to use the PUSHD function, which you can use to create a directory stack (a list in memory).

Note: By default, the PUSHD function may not be included in your Linux, but it is contained in red Hat and in a system driven by Red Hat. If you don't have a pushd function in your system, you can download the relevant function tools on the ibiblio.org Web site.

Here to say how to use pushd. Let's say you're working in the/usr/share/fonts directory. You need to make some changes to/usr/share/fonts and you will frequently switch between two directories. Start in one directory and switch to another directory with the PUSHD function. In our example, start with/usr/share/fonts, you type pushd/opt/wonderword/fonts, and then press ENTER. Now, you'll see the contents of the stack on the next line:

/opt/wonderword/fonts/usr/share/fonts

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

Quickly return to the previous level directory, you can type pushd directly, if not with the pathname, you will return to the stack in the previous directory of the previous level.

If you need to remove a directory from the stack, type popd, then the directory name, and then press ENTER. To view the list of directories in the stack, type dirs, and then press ENTER. The popd and dirs commands are also part of a common function.

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.