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 to switch directories with commands

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "how to use linux to switch directories with commands". 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!

1.cd-the function is to quickly switch to the previous directory, as follows:

The code is as follows:

Amosli@amosli-pc:~$ cd learn/fd/

Amosli@amosli-pc:~/learn/fd$ cd-

/ home/amosli

2.dirs: displays the directory stack, listing the directories saved in the current stack

The code is as follows:

Amosli@amosli-pc:~/learn/fd$ dirs

~ / learn/fd

Description: the-p parameter of dirs can display the list of directories in the stack in the form of one directory per line.

The-v parameter can be numbered before the directory

Note: when there is-v, you can display it in the form of a directory per line without adding-p.

The code is as follows:

Amosli@amosli-pc:~/learn/fd$ dirs-p-v

0 ~ / learn/fd

The directory on the stack is at the top

3. Introduction to the pushdpopd command

Pushd: switch to the directory as a parameter and push the original directory and the current directory into a virtual stack

If you do not specify a parameter, it goes back to the previous directory and swaps the two nearest directories in the stack

Popd: removes the most recent directory in the stack

The code is as follows:

Amosli@amosli-pc:/$ pushd bin/

/ bin /

Amosli@amosli-pc:/bin$ pushd / home/amosli/learn/fd/

~ / learn/fd / bin /

Amosli@amosli-pc:~/learn/fd$ dirs-p-v

~ / learn/fd

/ bin

/

Amosli@amosli-pc:~/learn/fd$ pushd / home/amosli/develop/

~ / develop ~ / learn/fd / bin /

Amosli@amosli-pc:~/develop$ dirs-p-v

~ / develop

~ / learn/fd

/ bin

/

The above uses the pushd command to push /, bin/, / home/amosli/learn/fd/, / home/amosli/develop/ onto the stack, which is a last-in, first-out (LIFO,last in first out) data structure.

So how do I change directories?

1) if it is a direct pushd with no parameters, you can switch to the nearest directory directly.

The code is as follows:

Amosli@amosli-pc:~/develop$ pushd

~ / learn/fd ~ / develop / bin /

Amosli@amosli-pc:~/learn/fd$

2) pushd + n

You can also follow the number and switch directly to the appropriate directory. For example, switch to / (root directory) as follows:

The code is as follows:

[code]

Amosli@amosli-pc:~/learn/fd$ pushd + 3

/ ~ / learn/fd ~ / develop / bin

Amosli@amosli-pc:/$ ls

How do I remove a directory?

1) popd directly removes the most recent directory

The code is as follows:

Amosli@amosli-pc:/$ dirs-p-v

0 /

1 ~ / learn/fd

2 ~ / develop

3 / bin

Amosli@amosli-pc:/$ popd

~ / learn/fd ~ / develop / bin

Amosli@amosli-pc:~/learn/fd$ dirs-p-v

0 ~ / learn/fd

1 ~ / develop

2 / bin

2) popd + n

Directly follow the number to remove the specified directory

The code is as follows:

Amosli@amosli-pc:~/learn/fd$ popd + 1

~ / learn/fd / bin

Amosli@amosli-pc:~/learn/fd$ dirs-p-v

0 ~ / learn/fd

1 / bin

This is the end of the content of "linux uses commands to switch directories". Thank you for your 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

Development

Wechat

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

12
Report