Linux switch path usage guide guide

  
                  As long as you have played the Linux command line, switching between directories is a piece of cake. The direct cd command is done, but in addition to the simple cd command, there are many other commands that can make your operation more convenient and faster. Suppose a situation, a file A is stored in the tenth directory directory ten, after a lot of hard work, it is not easy to enter the ten, the result is accidentally typed into a cd command, watching the cursor flash in the root directory, is Not very helpless? Is it necessary to go through a lot of paths and re-enter the ten directory? Don't bother with this, type “cd -” to see if you are back to the path just now? Note: "cd -” can complete the switch between the current directory and the previous directory. Another convenient path switch command is pushd, which can complete the switch between multiple different paths. If I want to be in /usr and /Switch between etc/ssh and /etc/rc.d and the current path, you can type it 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. Execute the dirs, you can see that the four paths are displayed: dirs/etc/rc.d /etc/ssh /usr ~ Input pushd, you can 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 clear these paths, Execute dirs -c. Dirs -cdirs/usr If you need to remove a directory from the stack, type popd, then the directory name, and press Enter to work in the Linux multi-directory command prompt, it's a pain, but the following use cd Tips for switching directories with pushd 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 usages of the cd command: change your root path, type cd, and press Enter. Go to a subdirectory, type cd, space, then the subpath name (for example: cd Documents), and press Enter. Go to the previous directory of the current directory, type cd, space, two dots, and press Enter. Go to a specific directory, type cd, space, pathname (for example, cd /usr/local/lib), and press Enter. To determine your directory, you can type pwd and press Enter. You will see the current directory name you are in. 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 wasting on repeated inputs. If these directories are not in the same root directory, you have to enter the full pathname during the conversion, which is inevitably unbearable. But you can avoid all the extra input with one or two of the following steps: use the history in the command line interpreter, or use the command line function pushd. The advantage of using history in the command line interpreter is that you only need to press very few keys. Use the up arrow on the command line to find the command you used until you find it, then press Enter. If the two directories you are switching are very close in the subdirectory structure of the entire drive, then using the history in the interpreter may be your best bet. However, if you are converting between two distinct paths, you might 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; however, it is included in Red Hat and Red Hat-powered systems. If you don't have a pushd function on your system, you can download the relevant function tools on the ibiblio.org website. Here to talk about how to use pushd. Suppose you are working in the /usr/share/fonts directory now. You need to make some changes to /usr/share/fonts and you will switch between the two directories frequently. Start in a directory and use the pushd function to switch to another directory. In our example, start under /usr/share/fonts, type pushd/opt/wonderword/fonts and press Enter. Now, you will 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, the content 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 typed (/opt/wonderword/fonts) is at the top of the stack. To quickly return to the previous directory, you can type pushd directly. If you don't follow the pathname, you will be returned to the previous directory in the previous directory on the stack. If you need to remove a directory from the stack, type popd, then the directory name, and press Enter. To see a list of directories in the stack, type dirs and press Enter. The popd and dirs commands are also part of the usual functions.
Copyright © Windows knowledge All Rights Reserved