Basic Linux Tutorial: fully learn the pwd command
For those who use Linux Command lines, the 'pwd' command is very useful and tells you how to get from the root directory (/) in that directory. Especially for Linux beginners who may be confused during directory switching, 'pwd' can save them.
What is pwd?
'Pwd' indicates 'print Working directory' (Print the current Directory ). Like its name, 'pwd' prints the current working directory, or simply the directory where the current user is located. It prints the complete directory name (absolute directory) starting from the root directory ). This command is a built-in shell command that can be used in most shells, such as bash, Bourne shell, ksh, and zsh.
Basic Syntax of pwd:
- # Pwd [OPTION]
Pwd options
| Option |
Description |
| -L (logical path logical) |
Use the path in the environment, even if it contains a symbolic link |
| -P (physical path physical) |
Avoid all symbolic links |
| -Help |
Show Help and exit |
| -Version |
Output version information and exit |
If '-L' And'-P' are used simultaneously, '-l' has a higher priority. If no parameter is specified, pwd avoids all soft links, that is, the '-p' parameter is used.
Exit status of pwd:
| 0 |
Successful |
| Non-zero value |
Failed |
The purpose of this article is to use examples to give you a deeper understanding of 'pwd.
1. Print the current working directory.
- Avi @ tecmint :~ $/Bin/pwd
- /Home/avi
Print working directory
2. Create a symbolic link for the folder (for example, create an htm Link under the home Directory to point to/var/www/html ). Enter the newly created directory and print the directory containing and without symbolic links.
In the home directory, create an htm link pointing to/var/www/html and enter.
- Avi @ tecmint :~ $ Ln-s/var/www/html/htm
- Avi @ tecmint :~ $ Cd htm
Create a symbolic link
3. Print the directory from the current environment even if it contains symbolic links.
- Avi @ tecmint :~ $/Bin/pwd-L
- /Home/avi/htm
Print working directory
4. parse the symbolic link and print out the physical directory.
- Avi @ tecmint :~ $/Bin/pwd-P
- /Var/www/html
Print the physical working directory
5. Check whether the outputs of "pwd" and "pwd-P" are consistent. That is to say, if "pwd" is not followed, the "-P" option is automatically used in "pwd.
- Avi @ tecmint :~ $/Bin/pwd
- /Var/www/html
Check pwd output
Conclusion: The output in Example 4 and 5 is obvious (the result is the same). If you do not include a parameter after "pwd", pwd uses the "-P" option.
6. Print the version of the pwd command.
- Avi @ tecmint :~ $/Bin/pwd -- version
-
- PWDs (GNU coreutils) 8.23
- Copyright (C) 2014 FreeSoftwareFoundation, Inc.
- LicenseGPLv3 +: gnu gpl version 3or later
- Thisis free software: you are free to change and redistribute it.
- Thereis no warranty, to the extent permitted by law.
-
- WrittenbyJimMeyering.
Check the pwd command version
Note: 'pwd' usually runs without any options and has no parameters.
Important: You may have noticed that we were running "/bin/pwd" instead of "pwd ".
What is the difference? Directly Using "pwd" means using the built-in shell pwd. Your shell may have different versions of pwd. For more information, see the manual. When you use/bin/pwd, we call the binary version command. Although the binary version has more options, both of them can print the current directory.
7. Print all paths containing executable pwd
- Avi @ tecmint :~ $ Type-a pwd
- Pwd is a shell builtin
- Pwd is/bin/pwd
Print the executable file path
For more details, please continue to read the highlights on the next page: