Results 1 to 10 of 11
I have been trying to do this.. but I don't know why it doesn't work... anyone knows?
cd | pwd -LP
For some reason pwd -LP is not passed to ...
- 11-26-2010 #1Just Joined!
- Join Date
- Nov 2010
- Posts
- 5
piping cd and pwd
I have been trying to do this.. but I don't know why it doesn't work... anyone knows?
cd | pwd -LP
For some reason pwd -LP is not passed to the cd command... please help

- 11-26-2010 #2
This is probably because this command pipes the output of 'cd' into 'pwd -LP', not the other way around...
Linux user #126863 - see http://linuxcounter.net/
- 11-26-2010 #3Just Joined!
- Join Date
- Nov 2010
- Posts
- 5
Well pwd -LP | cd doesn't work either... so what should I write in that case?!
- 11-26-2010 #4
Have you actually read the man page for pwd? I'm sure you realise that it works perfectly but what you're doing has no effect?
pwd stands for 'print working directory' - i.e. the current directory. If you then cd to it - you're back where you started.Linux user #126863 - see http://linuxcounter.net/
- 11-26-2010 #5Just Joined!
- Join Date
- Nov 2010
- Posts
- 5
Well, I guess this is not such a newbie question after all, because there are cases when you are wrong.... pwd -LP list the full path to where I am... if I followed a link to go there... the location will be for example /mylink/logs/ but the real full path which pwd -LP will give is /somefolder/another/folder/logs/
So what I have to do now... is if I do it manually write pwd -LP cut the result... after that write cd <paste the result> .... this takes a lot of time.
So why is it useful to cd to the full path... because if I write cd.. when I followed the link it takes me back to the place I was before following the link, but if I write cd .. after having cd the full link.. it takes me one step back in the directory structure.
So no my problem is NOT solved... still need help.
- 11-27-2010 #6Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,695
Google: bash return to previous directory
Code:pushd/popd Bash will keep a history of the directories you visit, you just have to ask. Bash stores the history in a stack and uses the commands pushd and popd to manage the stack. pushd dir - move the current directory onto the stack and change to the dir directory. popd - pops the top directory off of the stack and moves you into it. We’re opening files all over the file system, internal code, vendor code, templates, configuration files, logs. Because of this we like the ability to take a detour on the file system and still navigate back to our working directory of the day. I think these commands are so useful that I alias’d them in my .bashrc alias cd="pushd" alias bd="popd" Now the cd command manages the stack for me as well as changing directories. Aliasing popd to bd is an easy to remember and easy to type way to move back up the stack, think “change dir” and “back dir”.
- 11-27-2010 #7
So. I understand what you are attempting to accomplish, so let's assume that is a reasonable request
.
The problem that you are encountering is the way that piping works.
In your example:
You are taking the output of "pwd -LP", which is the resolved-link version of your PWD, and making it the input to cd.Code:pwd -LP | cd
But "cd" actually does not read any input. "cd" works by reading its commandline arguments. So although you have set up the pipe correctly, cd does not work the way you are expecting.
The correct way to do what you want is:
This executes the command "pwd -LP", and replaces the $(...) bit above with the output of that command. So cd will be executed with a commandline argument which is the output of "pwd -LP".Code:cd $(pwd -LP)
Does that make sense?DISTRO=Arch
Registered Linux User #388732
- 11-29-2010 #8
Hmmm, not exactly.
does what you require. The -L and -P options do the opposite of each other, -P tells pwd to dereference symlinks and show the absolute path, while -L tells pwd to show output using the symlinked versions. Interestingly, the last one is the one that takes priority - on my CentOS system here, -PL behaves like -L, while -LP behaves like -P.Code:# pwd -P
I didn't know that about 'cd' though; just like you I thought it behaved just like any other BASH command.Linux user #126863 - see http://linuxcounter.net/
- 11-29-2010 #9Linux user #126863 - see http://linuxcounter.net/
- 11-29-2010 #10Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,695


Reply With Quote
