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:
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.
$ ls -l lrwxrwxrwx 1 root 8 Sep 12 13:16 program -> software drwxr-xr-x 7 Apache users 4096 Feb 1 2013 software
$ cd /home/program
$ pwd /home/program
$ pwd -L /home/program
$ pwd -P /home/software
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:
$ PS1= "[ u@ h W] $"
This line will produce a shell prompt like this:
[uira @maquina learnlinux] $
By changing the “W” to “w”, you can obtain the full path of the current directory:
$ PS1= "[ u@ h w] $"
This way, we have the prompt:
[uira @maquina /home/learnlinux] $
To make this change permanent, you can add this line to the .bashrc file in the user’s HOME directory:
echo 'PS1= "[ u@ h w] $ “'>> ~/.bashrc
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:
[uira @maquina /home/learnlinux] $ cd /var/log/nginx [uira @maquina /var/log/nginx] $ cd - /home/learnlinux [uira @maquina /home/learnlinux] $ cd - /var/log/nginx [uira @maquina /var/log/nginx] $
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.
The shortcut with the “~” sign can be used to reference the logged-in user’s home directory:
$ cd ~ $ pwd /home/uira
The sudo command on Linux executes a given command as if it were another user.…
The ss command on Linux is extremely useful for investigating sockets, providing various information about…
Free Linux command shows the amount of total memory in use and available, as well…
The shell has structures for testing conditions and executing certain program sequences several times (loop),…
The /etc/fstab file stores the configuration of which devices should be mounted and what is…
The Netcat Command in Linux or nc is a utility used to do “almost anything”…
This website uses cookies.