Have you ever come across the need to know the current directory no knowledge? There is no want to copy the current directory hierarchy but do not know how to start? As the saying goes Ask a police officer for help, want to know the directory hierarchy natural looking pwd. So the question is:
What is pwd
pwd meaning Print Working Directory, print working directory is intended as the name suggests, that prints the user's current directory, it will print out from the root directory (/) to the beginning of the current full path to the directory where. This command is a shell built-in commands, and can be used in most of the shell, such as bash, Bourne shell, ksh, zsh, and so on.
# Pwd [OPTION]
-L (Ie logical path logical) path using the environment, even if it contains a symbolic link
-P (Ie, the physical path physical) to avoid all symlinks
-help display this help and exit
-version output version information and exit
If you use the '-L' and '-P', '- L' will have a higher priority. If you do not specify the parameters, pwd would avoid all symbolic links, that will use the '-P' parameter. Well, Here are the specific chestnuts. Our chestnuts are using the "/ bin / pwd" of. It and "pwd" What difference does it make?
With distinction pwd / bin / pwd of
What's the difference? Direct use "pwd" means using shell built-in pwd. Your shell may have a different version of pwd. For details, please refer to the manual. When you use the / bin / pwd, we call the binary version of the command. Although the binary version has more options, but they both can print the current directory. Well, Let's continue our pwd chestnuts combat.
8 pwd command chestnuts
1. Print the current directory:
1 linuxhost @ linuxhost: ~ $ / bin / pwd
3 / home / linuxhost
2. Create a symbolic link to the folder (for example, htm create a link to the / var / www / html in the home directory). Into the newly created directory and print out containing and free of symbolic links directory:
1 linuxhost @ linuxhost: ~ $ ln -s / var / www / html / htm
2 linuxhost @ linuxhost: ~ $ cd htm
3. To print from the current environment, even if it is a directory containing a symbolic link:
1 linuxhost @ linuxhost: ~ $ / bin / pwd -L
3 / home / linuxhost / htm
4. resolves all symbolic link to print the current actual physical directory:
1 linuxhost @ linuxhost: ~ $ / bin / pwd -P
3 / var / www / html
5. Print version pwd command:
1 linuxhost @ linuxhost: ~ $ / bin / pwd --version
3 pwd (GNU coreutils) 8.23
4 Copyright (C) 2014 Free Software Foundation, Inc.
5 License GPLv3 +: GNU GPL version 3 or later .
6 This is free software: you are free to change and redistribute it.
7 There is NO WARRANTY, to the extent permitted by law.
9 Written by Jim Meyering.
6. Print all paths containing the executable pwd:
1 linuxhost @ linuxhost: ~ $ type -a pwd
3 pwd is a shell builtin
4 pwd is / bin / pwd
7. The value of the variable to store "pwd" command (for example: a), and print from the value of the variable (for observation shell script is very important).
1 linuxhost @ linuxhost: ~ $ a = $ (pwd)
2 linuxhost @ linuxhost: ~ $ echo "Current working directory is: $ a"
4 Current working directory is: / home / linuxhost
8. Disposable obtain the current working directory and a directory of the previous work:
1 linuxhost @ linuxhost: ~ $ echo "$ PWD $ OLDPWD"
3 / home / home / linuxhost