Questions tagged [cwd]

current working directory of a process

Current working directory of a process, abbreviated cwd or wd or pwd (originally “print working directory” and backronymed to “present working directory”).

The cd command in a shell, or the chdir system call, change the working directory of the calling program. The current working directory of a shell can be seen with the pwd command or in the $PWD variable.

37 questions
277
votes
7 answers

Find out current working directory of a running process?

What command(s) can one use to find out the current working directory (CWD) of a running process? These would be commands you could use externally from the process.
slm
  • 363,520
  • 117
  • 767
  • 871
54
votes
2 answers

Resolving symbolic links (pwd)

Say I do the following: cd /some/path ln -s /target/path symbolic_name If then do: cd /some/path cd symbolic_name pwd I get: /some/path/symblic_name and not: /target/path Is there a way to have the shell "fully resolve" a symbolic link (i.e.…
Amelio Vazquez-Reina
  • 40,169
  • 77
  • 197
  • 294
22
votes
4 answers

Is there a POSIX (or at least a popular) utility to set the current working directory when invoking a program?

We have env(1) to modify the environment of the command we want to run (for example env MANPAGER=more man dtrace). Is there something similar but for modifying the directory that the command is going to be started in? Ideally, I would like it to…
Mateusz Piotrowski
  • 4,623
  • 5
  • 36
  • 70
17
votes
2 answers

Create an absolute symbolic link to the current directory

I am now under a directory with very long path. For future visiting it quicker, I would like to create a link to it. I tried ln -s . ~/mylink ~/mylink actually links to ~. So can I expand ~ into the obsolute pathname, and then give it to ln?
Tim
  • 98,580
  • 191
  • 570
  • 977
13
votes
2 answers

Why do all users start in /root instead of their home directories after su as root?

I feel like this should be straightforward but I've never seen anyone ask this that I can tell. The situation is pretty straight forward. Whenever I become a user, ie su user it always starts in /root directory instead of it's home directory. Let me…
Chris Jones
  • 233
  • 2
  • 5
8
votes
1 answer

Can I create a one way symlink?

I want to create a one way symlink i.e. I can use it to go to the destination directory but I cannot go back. Let's say there is a directory called D with two subdirectories S1 and S2. I want to create a link in S1 that points to S2 (let's say ls2…
WYSIWYG
  • 363
  • 2
  • 3
  • 9
8
votes
3 answers

`/proc/$PID/cwd` : is there a POSIX equivalent?

Linux has a /proc directory and file‑system, which as far as I can tell, is not part of POSIX. In each /proc/$PID subdirectories, is a symbolic link, cwd, pointing to the actual working directory of the process of this PID (the cwd link is always up…
Hibou57
  • 845
  • 2
  • 9
  • 20
7
votes
1 answer

Changing the current working directory of a certain process

Can I change the current working directory of a certain process? For example, I am running a process that has the pid 1000. Right now, its current working directory is ~. I want to change its current working directory to ~/1. How can I do it?
v7d8dpo4
  • 668
  • 5
  • 12
6
votes
1 answer

Making 'pushd' directory stack persistent

Ok this is a short question. I just happened to know that with pushd command, we can add more working directories into our list, which is handy. But is there a way to make this list permanent, so it can survive reboots or logoffs?
Sollosa
  • 1,887
  • 4
  • 19
  • 32
5
votes
1 answer

What is the difference between cwd and pwd?

What is the difference between cwd and pwd? I've tried googling it, and one of the answers mentioned that depending on some factor (which I sadly do not remember), the implementation (the code I'm assuming) is not the same? I don't suppose this is…
account
  • 53
  • 1
  • 4
5
votes
2 answers

Meaning of statement that 'getcwd functions work correctly' in FreeBSD man page for mount_nullfs?

In FreeBSD, man mount_nullfs states that: The primary differences between a virtual copy of the file system and a symbolic link are that the getcwd(3) functions work correctly in the virtual copy, and that other file systems may be…
Stilez
  • 1,221
  • 14
  • 28
5
votes
3 answers

"ls $PWD" and "ls ." get different files, strange caching perhaps?

I have a strange problem on my Linux Mint machine (with solid-state drive if that matters). Somehow the machine (on multiple occasions) gets different files, and different content for the same file, if I do "ls $PWD" instead of "ls ." or just "ls".…
3
votes
0 answers

Shell: Mounting to CWD does not update in shell session

When mounting a partition into my CWD (mount /path/do/devxy $(pwd)), the current shell session does not recognize it, e.g. find does not show any contents of the partition and umount $(pwd) succeeds despite me being in the directory (keeping it…
FelixJN
  • 12,616
  • 2
  • 27
  • 48
3
votes
1 answer

How can I make pwd resolve a soft link?

On one of our servers, we have a directory with the following path: "/daten/i/scripts" When you go to /daten/i, one can see that scripts is a soft link to "/batch". When I type cd /daten/i/scripts and then pwd, I see /daten/i/scripts. Is there a…
Wolfgang Adamec
  • 1,353
  • 4
  • 12
  • 14
3
votes
3 answers

Run a shell script via a symbolic link from the directory containing the script itself

My desire is not to change directory then execute. I use a jar file and need to execute that. So I made a very basic shell script to do that. #!/bin/sh java -jar TreeForm.jar Then, I saved it as TreeForm, not TreeForm.sh. Next, I created a symbolic…
Eray Erdin
  • 155
  • 1
  • 2
  • 8
1
2 3