Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux basis: a comprehensive study pwd command     - iSCSI + multipath achieve DM multipath storage (Server)

- To configure parameter configuration and software installation and uninstallation under Linux (Linux)

- Linux system started to learn: how to view the Linux thread of a process (Linux)

- Log in CentOS 6.5 Multi-user setting VNC (Server)

- xCAT error Unable to dispatch hierarchical sub-command to NORESOLUTION: 3001 (Linux)

- AngularJS asynchronous service testing and Mocking (Programming)

- CentOS 6.4 installation and configuration LNMP build PHP server runtime environment (Server)

- Talking about the implementation and the JVM garbage collection mechanism (Programming)

- grep, egrep and regular expressions (Linux)

- How to configure a development environment elegant Lua (Linux)

- MySQL display operation control tips (Database)

- TCP network communication Java Programming (Programming)

- How to use static, class, abstract method in Python (Programming)

- MySQL optimization of the relevant Group By (Database)

- git checkout generated in the use of temporary br (Linux)

- Android use canvas board painting (Programming)

- Ubuntu15 core CLR (Server)

- Oracle 11g How dataguard master repository to Oracle single instance data recovery (Database)

- How to configure security services under Linux (Linux)

- Oracle 11g RMAN virtual private directory (Database)

 
         
  Linux basis: a comprehensive study pwd command
     
  Add Date : 2017-08-31      
         
         
         
  For those who use the Linux command line is, 'pwd' command is very useful, it tells you that you are now in the directory from the root directory (/) how to reach. Especially for switching between directories might easily confused Linux novice, 'pwd' can save them.

What is pwd?

'Pwd' stands for 'Print Working Directory' (Print catalog). As its name implies, 'pwd' will print out the current working directory, or simply means that the user is currently located. It will print a complete directory name (absolute directory) to the root directory (/) as a starting point. 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 basic syntax:

# Pwd [OPTION]
pwd option

 Option Description
 -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 will avoid all soft link, that will use the '-P' parameter.

pwd exit status:

0 Success
Nonzero value failed
The purpose of this Title is to use examples to get you 'pwd' have a deeper insight.

1. Print the current working directory.

avi @ tecmint: ~ $ / bin / pwd
/ Home / avi

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 symbolic links and free directory.

Htm create a link to the / var / www / html in the home directory and enter.

avi @ tecmint: ~ $ ln -s / var / www / html / htm
avi @ tecmint: ~ $ cd htm

3. Print Directory even though it contains a symbolic link from the current environment.

avi @ tecmint: ~ $ / bin / pwd -L
/ Home / avi / htm

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

avi @ tecmint: ~ $ / bin / pwd -P
/ Var / www / html

5. check "pwd" and "pwd -P" output is consistent, that is, if there is no option to keep up, "pwd" automatically when using the -P option.

avi @ tecmint: ~ $ / bin / pwd
/ Var / www / html


Conclusion: The above example output 4 and 5, it is clear (same result), when you "pwd" Without an argument later, pwd will use the "-P" option.

6. Print pwd command version.

avi @ tecmint: ~ $ / bin / pwd --version
 
pwd (GNU coreutils) 8.23
Copyright (C) 2014FreeSoftwareFoundation, Inc.
LicenseGPLv3 +: GNU GPL version 3or later < http://gnu.org/licenses/gpl.html>.
Thisis free software: you are free to change and redistribute it.
Thereis NO WARRANTY, to the extent permitted by law.
 
WrittenbyJimMeyering.

Note: 'pwd' generally run with no options and no arguments

Important: You may have noticed that we just are running "/ bin / pwd" instead of "pwd".

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.

7. Print all paths containing the executable pwd

avi @ tecmint: ~ $ type -a pwd
pwd is a shell builtin
pwd is / bin / pwd


8. 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).

avi @ tecmint: ~ $ a = $ (pwd)
avi @ tecmint: ~ $ echo "Current working directory is: $ a"
Current working directory is: / home / avi

The following examples can also use printf instead.

9. The working path is switched to another place (for example, / home), and displayed in the command line. By executing the command (for example, 'ls') to verify everything OK.

avi @ tecmint: ~ $ cd / home
avi @ tecmint: ~ $ PS1 = '$ pwd>' [Note the example of single quotes]
> Ls

10. Set the multi-line display (like this below),

/ Home
123 # Hello #!
Then execute the command (for example, ls) to test everything OK.

avi @ tecmint: ~ $ PS1 = '
> $ PWD
$ 123 # Hello #!
$ '
 
/ Home
123 # Hello #!

11. Check the current working directory and all of a sudden the previous working path.

avi @ tecmint: ~ $ echo "$ PWD $ OLDPWD"
/ Home / home / avi

12. pwd absolute path of the file (in / start).

/ Bin / pwd
13. pwd absolute path to the source file (in / start).

/usr/include/pwd.h
Absolute path 13. pwd manual (start with /).

/usr/share/man/man1/pwd.1.gz
15. Write a shell script that analyzes a directory in your home directory (eg tecmint). If the current directory is tecmint outputs "Well! You are in tecmint directory" then output "Good Bye", otherwise they create a directory tecmint below and prompts you cd into it.

Let's first create a 'tecmint' directory, create a script file called 'pwd.sh' in the following.

avi @ tecmint: ~ $ mkdir tecmint
avi @ tecmint: ~ $ cd tecmint
avi @ tecmint: ~ $ nano pwd.sh
Next, add the following script pwd.sh in.

#! / Bin / bash
 
x = "$ (pwd)"
if [ "$ x" == "/ home / $ USER / tecmint"]
then
{
echo "Well you are in tecmint directory"
echo "Good Bye"
}
else
{
mkdir / home / $ USER / tecmint
echo "Created Directory tecmint you may now cd to it"
}
fi
Give execute permissions and run.

avi @ tecmint: ~ $ chmod 755 pwd.sh
avi @ tecmint: ~ $ ./pwd.sh
Well you are in tecmint directory
GoodBye

to sum up

pwd is one of the most simple and will be widely used in the command. Master pwd is the basis for the use of Linux terminal. That's it. I'll keep you bring another interesting article, please do not go away Stay tuned.
     
         
         
         
  More:      
 
- Build Golang development environment configuration on Ubuntu 14.04 (Linux)
- Depth understanding of Python character set encoding (Programming)
- Linux Basic Course: Install the software from source code (Linux)
- Oracle: RETURNING clause (Database)
- Ubuntu server 8.04 Firewall Guide (Linux)
- QEMU code analysis: BIOS loading process (Linux)
- JavaScript in null undefined summary (Linux)
- Why everybody ought to know LLVM (Linux)
- Git large file storage will help handle large binary files (Linux)
- Linux Firewall Basics (Linux)
- MySQL backup tool to back up mydumper (Database)
- EXP-00091: Exporting questionable statistics Processing Method (Database)
- Linux process scheduling opportunity (Programming)
- How to make a U disk to install Ubuntu (Linux)
- Bash variable expansion modifier (Programming)
- Forgot Linux root password (Linux)
- MySQL partition summary (Database)
- shell script: a key optimization CentOS system (Linux)
- shell script: a key to install LAMP, LNMP script (Server)
- Android Dynamic efficiency articles: a brilliant Loading Analysis and Implementation (Programming)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.