In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how to understand pwd and cd commands. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's follow the editor to have a look.
Introduction to 01 command
Today we will talk about the PWD command and the cd command.
Pwd command-returns the name of the current working directory.
Cd command-- change the working directory.
What is the working directory?
For example: if I work in Beijing, my place of work is Beijing; later, when I go to work in Shanghai, my place of work becomes Shanghai.
In linux, the directory under which we are currently located is called the current working directory, because all our commands (work) are executed in the current directory.
02 order detailed explanation
Grammar
Pwd [options] cd [options] [contents]
The pwd command has only options and no arguments. Because its function is to output the name of the current working directory, no parameters are required.
The cd command, with both options and parameters. Parameter is the name of the directory you want to switch to.
Parameters.
The pwd command has no arguments
Pwd
The pwd command prints out the name of the directory we are currently in.
As you can see, we are currently in the root directory.
The argument to the cd command is the directory name, which, after all, is used to switch working directories.
Let's start with four special commands.
Cd.
Last time we said "." The directory represents the current directory, so this command means to switch to the current directory.
Before executing the cd command, we are in the root directory. Execute "cd." After the command, we are still in the root directory.
But we are already in the current directory, and then switch to the current directory, a bit superfluous. So this command is not usually used.
And then "cd..." Orders.
Cd..
".." The directory represents the parent directory, or parent directory. So this command means to change to a directory one level above the current directory.
As you can see, we are currently in the root directory. Executing "cd..." After the command, we went from the root directory to the "/" root directory.
Then use the ls command introduced earlier to list the files and directories in the current directory and find the root directory lying quietly in it. The root directory is a subdirectory of the "/" root directory, so the cd command changes to the root directory.
Why don't we switch to the parent directory of the root directory?
Found that after switching to the root directory, and then to the parent directory of the root directory, the result returned is still the root directory.
What's going on? Have you been ordered to freak out?
This is because in Linux, the "/" root directory is the highest directory of the system, and it has no parent directory, so no matter how much you switch, the parent directory will stop the "/" directory. The knowledge of catalogue will be explained to you later.
Tip: to get the name of our current work directory, we don't have to use the pwd command, we can also check the shell prompt.
What is the shell prompt?
We open the terminal, and this is the shell prompt in the red box. Its default composition is generally
Current login user name @ hostname: current directory [$| #]
We only need to look at the directory in the shell prompt to know the current working directory, isn't that much more convenient? And the shell prompt can be customized, we can customize the shell prompt according to our custom, which is convenient for daily work.
In addition, the shell prompt finally displays "$" or "#", depending on the user who logged in. The logged-in user is displayed as "#" if it is a superuser root, or "$" if it is an ordinary user. Linux's superuser root is the equivalent of Windows's Administrator.
Here I logged in with the superuser root, so the shell prompt ended up with "#".
Next, I'd like to introduce you to a fun order.
Cd-
This command means to switch to the last directory we stayed in, or to understand that we will switch back to the directory from which we switched.
In the words of Bodhi Master, "Wukong, go back to where you come from."
At first we were in the root directory and changed to the root directory. Then execute the "cd -" command in the root directory and switch back to the root directory, because we stayed in the root directory before we came to the root directory. Run the same directory in the root directory and switch back to the root directory, because we were in the root directory before we came to the root directory.
It's kind of like an endless cycle.
Finally, the "~" directory is introduced.
Cd ~
In Linux, "~" represents the user's home directory.
In a multi-user operating system, each user is assigned a directory as a home directory to save the user's files.
In Linux, there are two types of home directories: the home directory of the average user and the home directory of the superuser.
Ordinary user: / home/ username Super user: / root
The home directory of an ordinary user is / home/ user name. If the user is admin, its home directory is / home/admin.
The same is true in Windows, except that the path is different. In addition, the same is true for Wechat and QQ. For example, QQ will store files for different users with the QQ number as the directory. Alumni who haven't noticed before can operate it on their own computers.
The superuser's home directory is / root. The superuser can view the home directory of the ordinary user, while the ordinary user cannot view the home directory of the superuser.
As you can see, executing the "cd ~" command has the same effect as executing the "cd / root" command. Because I logged in as a root user, the "~" directory is the root directory.
In addition, you can use "cd ~ user name" to switch to another user's home directory.
Of course, you can not specify a directory, in which case the cd command will switch to the home directory of the currently logged-in user, which has the same effect as the "cd ~" command.
After the introduction of the four special commands, let's introduce the method of switching between regular directories.
There are two ways to switch regular directories: relative path and absolute path.
In the study of physics, I believe everyone has come into contact with the reference. In Linux, relative and absolute paths are also related to the reference.
This is the structure of the tomcat directory: in the vulhub-master directory of the root directory under the root directory. Let's enter the tomcat directory with relative and absolute paths, respectively.
The reference to the relative path is the current working directory. If you switch using a relative path, the directory path starts with the current working directory.
You can also "go up against the current" and change to another directory.
We are currently in the tomcat directory.
".. /.. / Desktop" means the Desktop directory under the parent directory of the parent directory.
The parent directory of the tomcat directory is the vulhub-master directory, and the parent directory of the vulhub-master directory is the root directory, and then change to the Desktop directory under the root directory.
The above is a case of switching using a relative path, and here is how to switch a working directory using an absolute path.
As mentioned earlier, the highest directory for Linux is the "/" directory, all Linux files and directories are in the "/" directory, and the reference to the absolute path is the "/" directory.
If you want to switch directories using absolute paths, it's simple to follow that the path to the directory must start with the "/" directory.
No matter which path is used, as long as the path is correct, the same goal can be achieved.
Option
Both the pwd and cd commands have options, but in daily work, the options for these two commands are rarely useful.
Because by default, these two commands are enough to meet our needs. So no longer elaborate here, interested alumni can consult the relevant materials.
03 summary of command options
Syntax: pwd [option] cd [option] [directory] purpose: pwd---- prints the current working directory cd---- switch working directory parameters: the pwd command has no parameters, and the argument of the cd command is the directory name other: cd. Switch to the current directory cd.. Switch to the parent directory cd-switch to the previous directory cd ~ switch to the home directory cd ~ user name switch to another user's home directory root user: shell prompt ends with # Ordinary user: the shell prompt finally shows that $root can view other users' home directories. Ordinary users cannot view the relative path of root's home directory relative to the current working directory, and the absolute path to the "/" directory. The above is how to understand the pwd and cd commands. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.