Introduction Show
The In this tutorial, you will learn to use the Prerequisites
pwd SyntaxThe
The available options are discussed in the following section. Exit Status The
pwd OptionsThe options provide additional functionality to the command. The
There are several ways to use the Example 1: Get Working Directory PathRunning the For example: The command outputs the current working directory absolute path. In this case, the home directory path. Note: An absolute pathname starts with the However, if you followed a symlink to the current directory, running
In the following example, we created a symbolic link to the current directory. Following the link and running the Example 2: Using the -P OptionThe For example: Even though a symlink was used to change the directory, the Example 3: Using the -L OptionThe The output lists the path with the symbolic link. Example 4: Print $PWD Variable ContentsThe
The command outputs the current working directory, including any symlinks, stored in the Example 5: Personalize pwd OutputPersonalize the The following example is a script where Follow the instructions below: 1. Open the terminal and create the script:
2. Add the following lines to the script:
3. Save the script and exit
4. Change file permissions to make the script executable:
5. Run the script:
The script outputs the current working directory with a personalized message. Example 6: Check pwd VersionThe Check which
The command outputs the binary Note: Use the Example 7: See Previous Working DirectoryThe
The command outputs the previous working directory. Example 8: See Help FileUse the
The output is a brief help file with a list of available options. Example 9: Use pwd in ScriptingIn this example, we created a
bash case statement that uses 1. Create a script using a text editor such as vi/vim:
2. Enter the lines below:
3. Save and quit vi by running:
4. Make the script executable with
5. Execute the script and choose an option:
For example: The script utilizes a case statement to offer three options and prints a corresponding output based on the answer. 6. Change the directory using a symlink, execute the script again and compare the outputs: The output shows the physical location, even though we used a symlink to change the directory. 7. Test the remaining options as well to see the result: Example 10: Set up an Alias for pwdCreate an alias that includes the
In the following example, the alias includes the
The output displays the physical location, although we followed a symlink to the current path. Conclusion This tutorial showed how to use the If you are interested in bash, see our tutorial for bash functions and how to use them. Alternatively, we recommend delving further into Linux commands in our list of all important Linux commands in one place. Which Linux command can be used to display the name of the current working directory pwd sudo chmod PS?pwd (print working directory) – The pwd command is used to display the name of the current working directory in the Linux system using the terminal. This is a shell building command that is available in most Unix shells such as Bourne shell, ash, bash, kash, and zsh.
Which Linux command can be used to display he name of the current working directory?The pwd command can be used to determine the present working directory. and the cd command can be used to change the current working directory.
What is pwd in Linux command?The pwd command writes to standard output the full path name of your current directory (from the root directory). All directories are separated by a / (slash). The root directory is represented by the first /, and the last directory named is your current directory.
How do I display the current directory in Linux?To determine the exact location of your current directory within the file system, go to a shell prompt and type the command pwd. This tells you that you are in the user sam's directory, which is in the /home directory. The command pwd stands for print working directory.
|