Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use linux cd to transform a working directory

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use linux cd to change the working directory". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

You can efficiently change the working directory by using the alias of the linux cd command.

When you encounter a very deep folder directory when changing a directory, you can use.\ or multiple..\ to reach the destination folder, as in the following case:

Code:

# mkdir-p

/ tmp/very/long/directory/structure/that/is/too/deep

# cd / tmp/very/long/directory/structure/that/is/too/deep

# pwd

/ tmp/very/long/directory/structure/that/is/too/deep

# cd.. /

# pwd

/ tmp/very/long/directory/structure

In the linux cd command, to avoid repeated use of cd.. Command, you can simplify the operation by using the following three methods of command aliases.

Method 1: use an alias using a cd similar to ".. n"

In the following example,.. 4 is used to navigate to the level 4 parent directory of the current directory,. 3 is used to navigate to the level 3 parent directory of the current directory, and.. 2 is used to navigate to the level 3 parent directory of the current directory

Level 2 parent directory. Add the following code to your ~ / .bash_profile file and log in again:

Code:

Alias.. = "cd.."

Alias.. 2 = "cd.. /.."

Alias.. 3 = "cd. /.. /.."

Alias.. 4 = "cd.. /.."

Alias.. 5 = "cd.. /.."

Use.. 4 to go to the level 4 parent directory of the current directory:

Reference:

# cd

/ tmp/very/long/directory/structure/that/is/too/deep

#.. 4

# pwd

/ tmp/very/long/directory/structure/

Method 2: use only dots as aliases

In the following example,. (5 dots) is used to navigate to the level 4 parent directory of the current directory. Navigating 5 points to the level 4 directory of the current directory is easier to remember. When

When you type 2 points, you think you have reached the superior directory, and then, each time you enter a point, the current directory state comes to mind. Used only

Before using the alias of point, * * use pwd to print the full path of the working directory on the screen, so that you can enter the point while looking at the full path.

Again, use. (4 dots) navigate to the level 3 parent directory of the current directory. Add the following code to the ~ / .bash_profile file and log in again:

Code:

Alias.. = "cd.."

Alias... = "cd.. /.."

Alias.... = "cd.. /.. /.."

Alias. = "cd.. /.."

Alias. = "cd.. /.."

5 dots are used to navigate to the level 4 parent directory of the current directory:

Reference:

# cd / tmp/very/long/directory/structure/that/is/too/deep

#.

# pwd

/ tmp/very/long/directory/structure/

Method 3: linux cd command follow point, cd.

This method is similar to method 2, except that the linux cd command name is added before the point, so that it is not easy to make mistakes when using it. Add the following to the ~ / .bash_profile file

And log in again:

Code:

Alias cd..= "cd.."

Alias cd...= "cd.. /.."

Alias cd....= "cd.. /.. /.."

Alias cd.= "cd.. /.."

Alias cd.= "cd.. /.."

Use cd. Navigate to the level 4 parent directory of the current directory:

Reference:

# cd / tmp/very/long/directory/structure/that/is/too/deep

# cd.

# pwd

/ tmp/very/long/directory/structure

In addition, there are other similar methods, such as the following form of "cdn":

Reference:

Alias cd1= "cd..."

Alias cd2= "cd.. /.."

Alias cd3= "cd. /.. /.."

Alias cd4= "cd.. /.."

Alias cd5= "cd.. /.."

Linux command is broad and profound, here the linux cd command alias can efficiently change the working directory, usually use CLI (Command Line Interface) you will find a lot of unexpected tips.

This is the end of the content of "how to use linux cd to change the working directory". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report