Questions tagged [pwd]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
42 views

Can't loop files using pwd if current directory has spaces in the path [duplicate]

I have the following bit of code in a bash script I've created. When I run it from a directory with no spaces in the path it works as expected, however if I run from a directory with spaces it fails. ...
0
votes
0answers
37 views

Subshell does not inherit PWD

Hi I am fairly new to Linux and I've been trying to SSH and CD in one line from Windows 10 into Ubuntu. One solution I thought to try was: ssh -t <ip address> "cd <directory>; bash" I've ...
1
vote
1answer
12 views

unbundling a file of here docs when file's directory is different from pwd

All, I have a file (called, say, bundled_file.txt) of here docs stored in a directory, and the file looks like this: cat > a.txt << 'eof' ... ... ... 'eof' cat > b.txt << 'eof' ......
1
vote
2answers
24 views

How to change user and keep current location?

I wonder how in one command I can switch to another user (in my case it is usually root) and still remain in the same location where I am before the change. I usually do it this way, unfortunately ...
1
vote
2answers
67 views

sh: is there a command to interactively edit the PWD?

I'm looking for a command that invokes readline or similar, primed with the current $PWD, to let the user edit the current directory, then cd to the edited value. E.g. > cd ~/a/b/c/d > pwd > ...
2
votes
1answer
93 views

Complete a command fully relative to a different directory

I have a function to run a single command in a different category. cd1 SOMEDIR MYCOMMAND ARG… is equivalent to (cd SOMEDIR && MYCOMMAND ARG…), with two advantages. It's slightly easier to type ...
0
votes
1answer
164 views

Difficulty in undersanding pwd command

I am writing pwd in terminal, and it is showing home/<my_username>. But I cannot physically find any directory with this path. To clear my confusion, I typed ls, but it shows the folders in my ...
0
votes
1answer
36 views

Specifying path to a file within a program command line

I am using a program called Diamond and I have a script that goes like this: cd /srv/scratch/myname/hello diamond blastp -d /srv/scratch/myname/goodbye/inputFile1.dmnd -q inputFile2.faa -o /diamond/...
2
votes
0answers
33 views

Add file to PATH only when in specific directory [duplicate]

Is it possible to make executable appear in the global search path when I am entering to the some specific directory and get it removed once directory changed again?
0
votes
1answer
220 views

tcl cd/pwd command with regard to real/symbolic path

When I work under tcl environment, once I cd to a directory, even if the path I specify is its symbolic link, then no matter whether I run pwd -L or pwd -P, they all return the absolute path. This is ...
0
votes
1answer
475 views

When can a “cd” command fail in a shell script and what can I do to remedy it?

I have a shell script that failed to finish last week; it was a failed "cd" command and it exits if it fails. The script is a bash shell script for configuring new Debian installs. Here is the full ...
0
votes
2answers
375 views

How to run a command with a different working directory?

I use this shell pipeline to get a SQL dump using the terminal: $ cd var/lib/mysql && mysqldump -uroot -p"craft" --add-drop-table craft > ~/../docker-entrypoint-initdb.d/base.sql &&...
1
vote
1answer
865 views

Use SCP from local machine to recursively copy current working directory to remote?

Trying to do something like (in pseudo-unix): scp -r <pwd> username@remote.com:~/<dirname of toplevel> In other words, I'm trying to copy the current directory I'm in locally (and the ...
0
votes
2answers
369 views

tmux change default working directory of a session without attaching

I'm looking for a way to do something like this without attaching to the session. tmux attach-session -c <directory> -t <session> ^^^^^^^^^^^^^^ Per tmux(1), there ...
11
votes
2answers
2k views

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 ...
1
vote
1answer
62 views

Remove all lines that contain $PWD

I have a file that contains paths - looks like this: /Users/a/Desktop /Users/a/Documents /Users/a/Documents/Work What would be the easiest way to remove all lines that contain the current directory (...
0
votes
1answer
220 views

Trying to remove current directory using rmdir

I created a directory dir at Desktop and then i keyed in cd dir so as to make dir as my current directory and then i typed in the terminal rmdir /home/user_name/Desktop/dir from the dir directory ...
-4
votes
1answer
173 views

Linux: How to display the output of both command who and pwd using 1 command [closed]

I tried: who & pwd and it output the result of pwd output: /root. May I know if I am right?
1
vote
2answers
45 views

Get container directory more easily

I have a bash script here: $GOPATH/ src/ build.sh and in build.sh I have: export GOPATH="$(cd $(dirname "$BASH_SOURCE") && pwd)" is there a shorter way to get the containing dir ...
-2
votes
1answer
56 views

A directory showing up in itself [closed]

I do cd ~ and then pwd. It shows /root. Then I do ls. It again shows root. This is NOT another directory with the same name because when I do cd root, it says -bash: cd: root: Not a directory. ...
0
votes
2answers
196 views

content from pwd and which failed with sed to be replaced [duplicate]

I have a file which has the following content: BWA='/software/bwa/bwa-0.7.12/bwa' SAMTOOLS='/software/samtools/samtools-1.3.1/samtools' The above tools are on my computer: which bwa => /work/...
1
vote
1answer
698 views

How to change working directory of a child process by posix_spawn? [closed]

In Linux (CentOS 7.5, kernel 3.10, gcc 7.3), is it possible to change the working directory of a child process created by posix_spawn before it runs a given process image (an executable)? If yes, how? ...
2
votes
2answers
1k views

how to run shell command inside awk

i am trying to change dir when from A path to B path like below pwd|awk '{if($1=="/") cd /tmp/}' awk: syntax error near line 1 awk: illegal statement near line 1 please suggest
2
votes
3answers
1k views

why piping pwd and echo does not work? [duplicate]

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. ...
0
votes
0answers
275 views

sudo start login shell (-i) and stay at current working directory

When I login to root via sudo -i sudo changes the working directory of new shell to root's home directory. I can use following commands to keep working directory of parent shell: sudo -s sudo su ......
1
vote
1answer
350 views

Change path directory bash.exe

I installed bash on my Windows machine, and now when I run the shell, the pwd is: /mnt/c/Windows/System32 How may I change this? I open this shell everyday to work, and the directory when I'm ...
3
votes
1answer
749 views

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: $ ...
-3
votes
2answers
39 views

In what cases may some programs require you to run them on a specific directory? [closed]

https://unix.stackexchange.com/a/76641/674 Create a short shell script to run your wine program in this directory, i.e. ~/bin/textaloud: #!/bin/bash cd "~/.wine/drive_c" exec wine "~/.wine/...
0
votes
2answers
1k views

Concatenate pwd and basename [closed]

I want to assign the path and file name to a variable: /path/to/myfile/file.txt For example MYFILE=$(pwd)$(basename) How can i do it ?
1
vote
1answer
317 views

How to make my PS1 bash session show the whole pwd at all times?

Relevant .bashrc section: if [ "$color_prompt" = yes ]; then if [[ ${EUID} == 0 ]] ; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] ' ...
29
votes
3answers
3k views

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 ...
1
vote
3answers
2k views

How to get pid number and folder where it works

How I can get PID number and folder where it works? If I run 2 same programs in different folders: /var/www/public_html/first_folder/test.jar <i>(it runs all the time)</i> /var/www/...
9
votes
1answer
466 views

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 ...
2
votes
1answer
259 views

pwd to return current path with “/” at the end

I want pwd to return /path/to/dir in the format /path/to/dir/ with the "/" at the end. Any ideas as to how I can accomplish this?
2
votes
1answer
89 views

How to find and print specific file paths with exclusions?

Goal: Output .txt file with the full directory path, including name, of all .html files except for those with "txt" or "text" in the .html file name. I found the following line gives me the desired ....
2
votes
2answers
272 views

How/where does the shell store environment variables?

So there's $PWD, $PATH, $USERNAME and all that. I've been working on my own shell and I've just today introduced environment variables. The way I'm doing it is by creating strings called pwd, path and ...
0
votes
1answer
733 views

calling $PWD from another script

Having some trouble getting $PWD to work inside a bash script... I have two scripts in the same directory: ~/outer.sh, ~/inner.sh. I use outer.sh to call inner.sh as follows: (outer.sh contents ...
1
vote
1answer
207 views

How can I set zsh to use physical paths?

In bash, I can put set -P in my .bashrc, and to use absolute paths. That is, if I change to a directory through a symbolic link, and then use cd .., it takes me to that directory's canonical parent, ...
0
votes
1answer
303 views

Parameters in bash $PS1 variable

Between the various parameters that can be included in the bash PS1 variable, \w expands the current working directory, with $HOME abbreviated with a tilde (uses the value of the PROMPT_DIRTRIM ...
1
vote
0answers
35 views

iterm syncing sessions across new tabs

When I open up new tabs in iterm and change a directory, it syncs the old tabs to that new directory. I don't want this behavior. I'd like it to preserve the session that it was on. What's the problem ...
-1
votes
4answers
3k views

Is there a difference between pwd and cd?

Is there a difference between pwd and cd (no arguments)? They both print the current directory's path but is there a subtle difference that I'm missing, and if so, when should I use which?
1
vote
1answer
759 views

moving subdirectories with the mv command

In the following structure, with a parent directory K and three subdirectories, D, H, and B, respectively, directly under it, my current directory is D. From there I need to move H as a subdirectory ...
1
vote
2answers
81 views

How to search string references in specified location?

I'm trying to find the occurrence of elements list(from a text file) in a directory. Below is the bash code I'm using, but I'm unable to get the output of grep command on to console. #!/bin/bash ...
18
votes
3answers
7k views

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 ...
0
votes
1answer
27 views

launch a script which requires to be launched from a specific path via crontab

I have a script which before being launched checks via pwd if the path upon launch is something specific (say dir/subdir/script) current_folder=$(pwd | grep dir/subdir/script) if [ "$current_folder" =...
33
votes
4answers
5k views

How to tell if I'm actually in a symlink location from command line?

Suppose I have a folder: cd /home/cpm135/public_html and make a symbolic link ln -s /var/lib/class . Later, I'm in that directory: cd /home/cpm135/public_html/class The pwd is going to tell me I'...
2
votes
1answer
123 views

Why does the pwd doesn't update after directory removal?

I tried a little experiment where I created 2 folders Dir1 and Dir2 inside my Desktop directory, such that Dir1 is parent of Dir2. /home/username/Desktop/Dir1/Dir2 Then, I use cd to set my pwd as /...
3
votes
1answer
127 views

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 ...
3
votes
3answers
2k views

Create history log per working directory in bash

I was wondering if it is possible to keep a file containing history per current working directory. So for example if I was working in /user/temp/1/ and typed a few commands, these commands would be ...
1
vote
3answers
2k views

Alias for “cd” which shows current directory each time I change directories?

In tcsh, I would like an alias to pwd after I cd to a different directory. Previously I used the below alias for this, but it also changes the shell prompt to be [current directory]>. Due to ...