What if the Linux directory is too long? Share a little bit of tricks

Source: Internet
Author: User

When Linux uses CD, may encounter the directory is deep, this time always CD a very long directory will be very troublesome, there is no more convenient method?

If you switch back and forth in two directories, you can use the CD-this command to switch back and forth in two directories, why use a CD-can you switch back and forth in two directories?

Because CD-equivalent to CD $OLDPWD

As the name implies, OLDPWD this variable holds the previous path value

But how often do you switch directories more than 2?

This time can use this pair of good pushd and popd to the directory of the switch, of course, but also need to add dirs

The pushd command may stack the current directory and jump to the specified directory

Usage: [Email protected]]# pushd path2

This time will be path1 directory stack, and jump to the path2 directory, using Dirs-v view will see the compressed stack directory information.

This way, if you press a path3, you will see the directory information using dirs-v:

0 Path3

1 path2

2 path1

The previous number is the ordinal number of these directories, use the pushd +n command to complete any directory jump, N is the directory number.

Then POPD is also easy to understand what it means, since pushd is the meaning of the address, then popd is the meaning of the pop dir, the same way you can use POPD +n the address out of the stack, if the current directory will be returned OLDPWD, Otherwise, only the values in the directory stack will be present in the stack.

Using pushd and popd can sometimes be more convenient than CDs, but I also like to switch directories in another way, using the Linux command alias

The syntax for this command is: alias [-p][alias][= Command]

This command is very useful and can be used to simplify some of the more cumbersome commands.

For example, I have a directory often used, but this directory path is longer, this use can use alias to improve efficiency

Alias cdpath= ' CD Longpath '

where Cdpath for their own alias, Longpath for the longer directory. This way, as long as the terminal-typed Cdpath can be done convenient jump

Of course, if this command is entered directly in the terminal, then the start of a new terminal fear will not be useful. So I'm going to write it into the BASHRC.

BASHRC generally under the/etc/directory

VI BASHRC, and insert the source etc/alias_cd.sh in the last line

VI alias_cd.sh, and in which to insert the directory needs alias, save the exit, the source BASHRC can

The use of Cdpath such a command can quickly switch to the desired directory, is not very convenient ~

Of course the way out of the CD directory, you can also use the alias command to alias many commands ~

What if the Linux directory is too long? Share a little bit of tricks

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.