What is pwd command?
In the Linux environment, knowing the exact location in the file system is essential for browsing, running scripts and managing files. The pwd command, acronym of «print working directory», is one of the simplest but most powerful tools the terminal offers. In this article we will explore its operation, syntax, options and some tricks that will make your daily work more efficient.
Basic syntax
The pwd command is invoked simply by writing:
pwd
This form shows the absolute path of the current directory, starting from the root of the file system (/). If you want to see the logical route, which respects symbolic links, you can use the -P option. By default, pwd shows the logical path (-L), but you can force physics with -P.
Examples of use
- Show the current directory:
$ pwd /home/usuario/documentos - Forging the physical route (ignoring symbolic links):
$ pwd -P /home/usuario/real_documentos - Use pwd in a script to build routes:
#!/bin/bash BASE=$(pwd) cp archivo.txt "$BASE/respaldo/" - Combine pwd with other commands:
ls -la $(pwd)
Useful options
Although pwd is simple, it has some options that can be useful:
-L: shows the logical route (default value).-P: shows the physical route, solving all symbolic links.--help: shows a brief help and comes out.--version: shows the command version and comes out.
In most distributions, the pwd version comes from the GNU choreutils package, so its behavior is consistent between systems.
Tips and tricks
- Customize the prompt:You can include pwd output in your PS1 variable to always see the current directory:
export PS1='\u@\h:\w\$ 'Here w already shows the directory, but if you prefer to use the command explicitly:
export PS1='\u@\h:$(pwd)\$ ' - Capture output in a variable:In scripts, saving the result prevents repeated calls:
DIR_ACTUAL=$(pwd) - Avoid surprises with symbolic links:If you work in directories that are links, remember to use -P when you need the real route.
- Compatibility:pwd works equally in bash, zsh, fish and other shells, which makes it portable.
Conclusion
The pwd command, despite its apparent simplicity, is an essential piece in the arsenal of any Linux user. Knowing when to use the logical path or physics, how to integrate it into scripts and how to customize your working environment will allow you to navigate with greater confidence and efficiency. Next time you wonder «Where are you?»Remember, pwd has the answer to a key's reach.


