Questions tagged [pwd]

`pwd` is a shell command for "print working directory". When issued, it prints the path of the current working directory.

131 questions
409
votes
10 answers

Windows equivalent to UNIX pwd

How do I find the local path on windows in a command prompt?
Joshua
  • 24,418
  • 22
  • 74
  • 106
158
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,177
  • 13
  • 43
  • 59
84
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,295
  • 7
  • 29
  • 41
75
votes
5 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,276
  • 8
  • 37
  • 56
39
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
  • 407
  • 1
  • 5
  • 9
30
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
  • 303
  • 1
  • 3
  • 4
18
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
  • 6,732
  • 11
  • 51
  • 92
17
votes
11 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
  • 229
  • 2
  • 4
  • 12
15
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
  • 107,447
  • 124
  • 346
  • 512
14
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,116
  • 1
  • 12
  • 27
11
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
  • 106,283
  • 107
  • 420
  • 616
11
votes
2 answers

How to copy to the clipboard the current path?

How can I copy the current path in the bash terminal, using just one command?
ziiweb
  • 28,757
  • 70
  • 168
  • 290
10
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
  • 751
  • 4
  • 13
  • 26
9
votes
2 answers

Collapse directories in zsh prompt in a unique way

Is there a way to collapse the current working directory in the zsh prompt in a unique way, so that I could copy and paste it to another terminal, hit TAB and get the original path? Let's say we have following…
eumiro
  • 179,099
  • 29
  • 277
  • 252
9
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
  • 91
  • 1
  • 1
  • 2
1
2 3
8 9