Basic Linux Tutorial: fully learn the pwd command

Source: Internet
Author: User

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:
  1. # 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.

  1. Avi @ tecmint :~ $/Bin/pwd
  2. /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.

  1. Avi @ tecmint :~ $ Ln-s/var/www/html/htm
  2. Avi @ tecmint :~ $ Cd htm

Create a symbolic link

3. Print the directory from the current environment even if it contains symbolic links.

  1. Avi @ tecmint :~ $/Bin/pwd-L
  2. /Home/avi/htm

Print working directory

4. parse the symbolic link and print out the physical directory.

  1. Avi @ tecmint :~ $/Bin/pwd-P
  2. /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.

  1. Avi @ tecmint :~ $/Bin/pwd
  2. /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.

  1. Avi @ tecmint :~ $/Bin/pwd -- version
  2.  
  3. PWDs (GNU coreutils) 8.23
  4. Copyright (C) 2014 FreeSoftwareFoundation, Inc.
  5. LicenseGPLv3 +: gnu gpl version 3or later
  6. Thisis free software: you are free to change and redistribute it.
  7. Thereis no warranty, to the extent permitted by law.
  8.  
  9. 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

  1. Avi @ tecmint :~ $ Type-a pwd
  2. Pwd is a shell builtin
  3. Pwd is/bin/pwd

Print the executable file path 

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.