Pwd command on Linux (current directory)
The pwd command reports the current absolute directory. Absolutely it is understood that it shows the complete path from the root of the system.
It has a few options:
- -L or —logical Lists the contents of the PWD variable, even if it contains symbolic links
- -P or —physical Avoid all symbolic links
In this example, the /home/program directory is the symbolic link for /home/software.
The pwd command without an option or with the “-L” option, the symbolic link is indicated.
With the “-P” option, pwd resolves the symbolic link pointing to the original directory.
The pwd is a command that can be widely used by programmers to check which current directory you are working in.
However, to make it even easier, this information can be placed on the command line by changing the shell’s PS1 variable:
This line will produce a shell prompt like this:
By changing the “W” to “w”, you can obtain the full path of the current directory:
This way, we have the prompt:
To make this change permanent, you can add this line to the .bashrc file in the user’s HOME directory:
Go to and back in Directories with the minus sign “-”
Another very useful shortcut for programmers are the exchange of directories between the current and the last directory, using the “-” option of the cd command:
Note that the “cd -” can make you go back and forth from one directory to another, saving you a lot of fingers, especially when you want to go back and forth from the application directory, and the logs directory, as in the example.
Home directory with the tilde sign “~”
The shortcut with the “~” sign can be used to reference the logged-in user’s home directory: