Bash current file directory
Set by the shell and by the cd utility. In the shell the value shall be initialized from the environment as follows. Otherwise, if a value for PWD is passed to the shell in the environment when it is executed, the value is an absolute pathname of the current working directory, and the value does not contain any components that are dot or dot-dot, then it is unspecified whether the shell sets PWD to the value from the environment or sets PWD to the pathname that would be output by pwd -P.
Otherwise, the sh utility sets PWD to the pathname that would be output by pwd -P. In cases where PWD is set to the value from the environment, the value can contain components that refer to files of type symbolic link.
In cases where PWD is set to the pathname that would be output by pwd -P, if there is insufficient permission on the current working directory, or on any parent of that directory, to determine what that pathname would be, the value of PWD is unspecified.
Assignments to this variable may be ignored. If an application sets or unsets the value of PWD, the behaviors of the cd and pwd utilities are unspecified. You need to use command substitution to save output of pwd command to a variable.
Command substitution can use backticks or dollar characters. Like this:. The value of the current working directory can be different. Since you are using bash, I would use:.
Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Learn more. Prev Next. Written by Gabor Szabo. If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub. Comment on this post. Gabor can help your team improve the development speed and reduce the risk of bugs. He is also the author of a number of eBooks. Contact Gabor if you'd like to hire his services.
If you would like to support his freely available work, you can do it via Patreon. You can also go back to your home directory e. The first step in creating a new directory is to navigate to the directory that you would like to be the parent directory to this new directory using cd. Then, use the command mkdir followed by the name you would like to give the new directory e.
For example, you can create a new directory under documents called assignments. Then, you can navigate into the new directory called assignments , and print the current working directory to check the new path. Notice that mkdir command has no output. Also, because assignments is provided to Bash as a relative path i. Data Tip: Directory vs Folder: You can think of a directory as a folder.
However, recall that the term directory considers the relationship between that folder and the folders within it and around it. Data Tip: Notice that you are creating an easy to read directory name.
The name has no spaces and uses all lower case to support machine reading down the road. To see a list of all subdirectories and files within your current working directory, use the command ls. In the example above, ls printed the contents of the home directory which contains the subdirectories called documents and downloads and the files called addresses. You can continue to change your current working directory to a subdirectory such as documents and print a new list of all files and subdirectories to see your newly created assignments directory.
You can also create a new subdirectory under assignments called homeworks , and then list the contents of the assignments directory to see the newly created homeworks. To delete a specific file, you can use the command rm followed by the name of the file you want to delete e.
For example, you can delete the addresses. To delete i. For example, you can delete the assignments directory under the documents directory because it does not meet the requirement of a good name for a directory i. The rm stands for remove, while the -r is necessary to tell Bash that it needs to recurse or repeat the command through a list of all files and sub-directory within the parent directory.
0コメント