I am facing a very confusing behaviour of ls
that I cannot search for. It displays that there are contents in a directory, but only when I'm in the directory where these were created from.
Let me show you:
ciprian Documents $ pwd
/Users/ciprian/Documents
ciprian Documents $ ls ../Downloads/rss22/
22rss-USB/
ciprian Documents $ ls ../Downloads/rss22/22rss-USB/
HTML/
ciprian Documents $ cd ../Downloads/rss22
ciprian rss22 $ ls
ciprian rss22 $ ls 22rss-USB/
gls: cannot access '22rss-USB/': No such file or directory
After I cd
ed to ../Downloads/rss22
, its contents are displayed as empty. It is also shown empty if I cd ~/Desktop
and then I ls ../Downloads/rss22/
, like the first case here.
To me, this indicates that there might be a folder named ../Downloads/rss22
inside Documents
. But I cannot figure out how to display it. ls -a ~/Documents
does not show anything related to these folders.
What is going on?
The files were created by trying a partial extraction from an archive: unzip 22rss-USB.zip "22rss-USB/HTML/**/*" -d ../Downloads/rss22/
For reference, I am on macOS, though I do not think this is relevant (it's a Unix, right?). I am using Bash 5.1.16 (changed from default zsh).
Output of type pwd
: pwd is a shell builtin.
It turns out that if I do cd -P ../Downloads/igarss22/
then it shows the contents that I expect. Where can I see more about this? man cd
doesn't show anything about -P
.
Now, after cd -P ../Downloads/igarss22/
ciprian Documents $ cd -P ../Downloads/igarss22
ciprian igarss22 $ pwd
/Users/ciprian/Library/CloudStorage/OneDrive/Downloads/igarss22
Right. So I forgot this ; my ~/Documents
is a symlink to a folder under my OneDrive:
$ ll ~/ | grep Doc
lrwxr-xr-x 1 ciprian 38 May 19 2022 Documents -> /Users/ciprian/OneDrive/Documents
Which, due to some magic and changes in macOS v12 (Monterey), actually lives under /Users/ciprian/Library/CloudStorage/OneDrive
.
I'm still not sure what exactly is going on
-P
option ofcd
make a difference?cd
/pushd
without -P treat..
differently from everything else. – Stéphane Chazelas Jan 09 '23 at 08:17pwd
really output~/Documents
? What doestype pwd
return? – Stéphane Chazelas Jan 09 '23 at 08:19-P
flag, it has cleared the confusion help cd -P. Would you care to draft an answer, so I can accept it and close the question ? – Ciprian Tomoiagă Jan 09 '23 at 09:20zsh
) has been the default shell since macOS v10.15 (Catalina) (2019). Monterey is from 2021. – Peter Mortensen Jan 09 '23 at 23:18