Questions tagged [pwd]

For questions about the working directory of processes, as well as the `pwd` command

The working directory is the starting directory when a process searches for relative paths. In shell, the pwd command prints the current working directory.

See also:

88 questions
82
votes
2 answers

Is it better to use $(pwd) or $PWD?

I encountered BASEDIR=$(pwd) in a script. Are there any advantages or disadvantages over using BASEDIR="$PWD", other than maybe, that $PWD could be overwritten?
Minix
  • 5,735
  • 8
  • 28
  • 45
43
votes
6 answers

Make pwd result in terms of "~"?

pwd gives me /data/users/me/some/random/folder Is there an easy way of obtaining ~/some/random/folder from pwd?
Sibbs Gambling
  • 1,646
  • 6
  • 20
  • 26
32
votes
1 answer

How to get the cd shell-builtin to stop guessing?

For example: $ ls -aF ./ ../ bin/ $ cd tin # with a tee, not bee bin $ pwd /home/user/bin In other words, cd guesses that what I really meant was cd bin, and successfully (huh?) changes the current directory accordingly. I do not find this behavior…
Ana Nimbus
  • 681
  • 4
  • 10
31
votes
3 answers

How does Unix keep track of a user's working directory when navigating the file system?

Say I log into a shell on a unix system and begin tapping away commands. I initially begin in my user's home directory ~. I might from there cd down to the directory Documents. The command to change working directory here is very simple intuitively…
marked-down
  • 431
  • 5
  • 8
21
votes
3 answers

PS1='$(pwd)' why this works and why is this different from PS1=$(pwd)

Why when I enter this command the prompt changes to my directory? PS1='$(pwd)' I am using single quotes, which means no interpolation , a.k.a echo '$(pwd)' ——→ $(pwd) Furthermore, say that we clarified why this works... why is it functioning…
HashWizard
  • 347
  • 1
  • 4
  • 12
18
votes
7 answers

Compact bash prompt when using a directory tree / filename

In a system with Ubuntu 14.04 and bash, I have the PS1 variable ending with the following contents: \u@\h:\w\$ so that the prompt appears as user@machinename:/home/mydirectory$ Sometimes, however, the current directory has a long name, or it is…
BowPark
  • 4,811
  • 12
  • 47
  • 74
17
votes
2 answers

Strange difference between pwd and /bin/pwd

I added a symlink to the current directory with ln -s . aa. If I execute cd aa, and after that I executed pwd, the response is /home/sim/aa. But if I execute /bin/pwd it prints /home/sim (the current directory hasn't changed). Where does this…
user3581976
  • 3,095
  • 3
  • 18
  • 19
15
votes
1 answer

Why did 'scp 10.0.0.11:/home/someuser/.*' start copying from /home as well?

I'm doing my first ever moving of user files from an old system to a new system. My goal is to use SCP for it's simple syntax of scp -r source destination. I tried the following command to copy the files first: scp -r [email protected]:/home/someuser/*…
Brian
  • 292
  • 3
  • 10
13
votes
4 answers

`ls` error when directory is deleted

I have two shells open. The first is in directory A. In the second, I remove directory A, and then recreate it. When I go back to the first shell, and type ls, the output is: ls: cannot open directory .: Stale file handle Why? I thought the first…
fonini
  • 324
  • 3
  • 13
12
votes
2 answers

Why pwd does not accept long options like --physical?

When I display the manual for pwd command, it says that long options like --physical are supported $ man pwd PWD(1) User Commands PWD(1) NAME pwd - print name of current/working…
Michal Kordas
  • 261
  • 3
  • 8
12
votes
3 answers

How can I run a command in bash after any change in $PWD?

zsh provides some nice hook functions, including chpwd for running a function after the user changes directories. # zsh only function greet() { echo 'hi'; } chpwd_functions+=("greet") cd .. # hi pushd # hi popd # hi I'm trying to emulate that in…
Nathan Long
  • 1,613
  • 1
  • 13
  • 27
9
votes
1 answer

Etymology of $PWD

What is the etymology of $PWD? Is it an acronym? I know there is a command pwd which prints working directory, but to my mind, it would have made more sense to name the variable $CWD for Current Working Directory, since shell variables contain data,…
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
8
votes
2 answers

A command that gives username@hostname:pwd

I know that pwd gives the current working directory, hostname gives the current host and whoami gives the current user. Is there a single unix command that will give me the output of whoami@hostname:pwd so that I can quickly paste the output into…
Hooked
  • 1,343
  • 3
  • 17
  • 24
7
votes
2 answers

What happens when the current directory is deleted?

In the first terminal A, I create a directory, enter the directory, and create a file: $ mkdir test $ cd test $ touch file1.txt $ ls file1.txt Then in another terminal B, I delete the directory: $ rm -r test $ mkdir test $ cd test $ touch…
wenzeslaus
  • 175
  • 5
6
votes
3 answers

why piping pwd and echo does not work?

I'm new to unix. I typed this command in ubuntu terminal: pwd | echo I expected to see the output of pwd in terminal(/home/fatemeh/Documents/Code/test) but the output was just a single empty line. why this happens?
Fatemeh Karimi
  • 168
  • 1
  • 7
1
2 3 4 5 6