`pwd` is a shell command for "print working directory". When issued, it prints the path of the current working directory.
Questions tagged [pwd]
149 questions
486
votes
12 answers
Windows equivalent to UNIX pwd
How do I find the local path on Windows in a command prompt?

Joshua
- 26,234
- 22
- 77
- 106
160
votes
4 answers
shell init issue when click tab, what's wrong with getcwd?
once i click Tab on bash, the error message will appear, what's wrong?
symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
symlink-hook: error retrieving current directory: getcwd:…

hugemeow
- 7,777
- 13
- 50
- 63
95
votes
3 answers
How do I change my pwd to the real path of a symlinked directory?
Here's a rather elementary *nix question:
Given the following symlink creation:
ln -s /usr/local/projects/myproject/ myproject
... from my home directory /home/jvf/, entering the myproject symlink gives me a pwd /home/jfv/myproject/. Now, I would…

Johan Fredrik Varen
- 3,796
- 7
- 32
- 42
90
votes
7 answers
How to run 'cd' in shell script and stay there after script finishes?
I used 'change directory' in my shell script (bash)
#!/bin/bash
alias mycd='cd some_place'
mycd
pwd
pwd prints some_place correctly, but after the script finished my current working directory doesn't change.
Is it possible to change my path by…

qrtt1
- 7,746
- 8
- 42
- 62
48
votes
4 answers
Extract the last directory of a pwd output
How do I extract the last directory of a pwd output? I don't want to use any knowledge of how many levels there are in the directory structure. If I wanted to use that, I could do something like:
> pwd
/home/kiki/dev/my_project
> pwd | cut -d'/'…

Siou
- 497
- 1
- 5
- 9
39
votes
3 answers
How do I execute a Shell built-in command with a C function?
I would like to execute the Linux command "pwd" through a C language function like execv().
The issue is that there isn't an executable file called "pwd" and I'm unable to execute "echo $PWD", since echo is also a built-in command with no executable…

user2851770
- 393
- 1
- 3
- 4
25
votes
1 answer
bash: What is the difference between PWD and CURDIR?
My Problem
I use a Makefile to run a docker run target, which needs the current working directory as one of its parameters.
I use either $(PWD) or $(CURDIR):
build: Dockerfile
docker run ... <$(PWD) or $(CURDIR)>
They seem to be producing…

Adam Matan
- 128,757
- 147
- 397
- 562
24
votes
12 answers
shell script: bad interpreter: No such file or directory when using pwd
I want to go through the files in a directory with a for loop but this comes up.
echo: bad interpreter: No such file or directory
code:
#!/bin/bash
count=0
dir=`pwd`
echo "$dir"
FILES=`ls $dir`
for file in $FILES
do
if [ -f $file ]
then
…

Alek
- 299
- 2
- 4
- 12
24
votes
5 answers
Getting directory from which node.js was executed
I have some project, and I run it with node main.js / make test etc. What I need is to get this directory from a script. Not only from main.js, but also from any submodule. I tried with path plugin and __directory, but I get a path of the current…

ciembor
- 7,189
- 13
- 59
- 100
15
votes
3 answers
How can NPM scripts use my current working directory (when in nested subfolder)
It's good that I can run NPM scripts not only from the project root but also from the subfolders. However, with constraint that it can't tell my current working path ($PWD).
Let's say there's a command like this:
"scripts": {
...
"pwd": "echo…

Allen
- 4,431
- 2
- 27
- 39
15
votes
3 answers
Bash script awkwardness with pwd
I've got a strange issue while working with a bash script. Here it is:
PWD=${pwd}
# several commands
cd /etc/nginx/sites-enabled/
# more commands
cd $PWD
# I expect that I returning to my directory,
# but $PWD contains current dir -…

Vasiliy Stavenko
- 1,174
- 1
- 12
- 29
13
votes
2 answers
When to use Absolute Path vs Relative Path in Python
For reference. The absolute path is the full path to some place on your computer. The relative path is the path to some file with respect to your current working directory (PWD). For example:
Absolute path:
C:/users/admin/docs/stuff.txt
If my PWD…

samGon
- 131
- 1
- 1
- 3
13
votes
2 answers
How to define pwd as a variable in Unix shell
I tried the following but it didn't work.
dir=$pwd
echo $dir
/bin/env/####/ --id --edition dir- $dir
I want to paste the current working directory into the above script.

Sathish
- 1,245
- 2
- 15
- 22
13
votes
2 answers
Get current directory of file after getting called by another bash script
So I have one bash script which calls another bash script.
The second script is in a different folder.
script1.sh:
"some_other_folder/script2.sh"
# do something
script2.sh:
src=$(pwd) # THIS returns current directory of script1.sh...
# do…

Travv92
- 791
- 4
- 14
- 27
12
votes
3 answers
Bash or-equals ||= like Ruby
Does Bash have something like ||= ?
I.e., is there a better way to do the following:
if [ -z $PWD ]; then PWD=`pwd`; fi
I'm asking because I get this error:
$ echo ${`pwd`/$HOME/'~'}
-bash: ${`pwd`/$HOME/'~'}: bad substitution
So, my plan is to…

ma11hew28
- 121,420
- 116
- 450
- 651