Why doesn't ls -la show that current directory is symlink?
May I answer with a question? Assuming you're on a RedHat/CentOS install here...
ls /etc/httpd/
# should return something like:
# conf conf.d logs modules run
cd /etc/httpd/logs/
# Why does this next command fail?
ls ../conf
# ls: cannot access ../conf: No such file or directory
# But this next command works?
cd ../conf
The short answer is when you're "inside" /etc/httpd/logs
(the symlink) you're actually inside /var/log/httpd
, which is a directory.
cd /etc/httpd/logs/
pwd
# /etc/httpd/logs
pwd -P
# /var/log/httpd
.
indicates the current directory. Once you cd
to a symlink, you are in the destination directory. What you are seeing is not an error, or a problem of any kind. This is how symlinks work in unix systems. If you want to see the symlink when you list files, then stay in the parent directory where the actual symlink exists.
By default, cd
is going to "follow" the symlink, but it then sets the PWD
systems variable with /etc/httpd/logs
. So that way when you do cd ..
it uses the PWD variable for reference. ls
won't. It grabs the physical location of where you're at (/var/log/httpd), just like /bin/pwd
but shell builtin pwd uses the $PWD variable.
So when you cd into /etc/httpd/logs, you actually go to /var/log/httpd. Thats why when you do ls -la
, you see . as a directory and not a symlink. Then when you use cd to back out, it remembers that you were in /etc/httpd and uses that as the reference.
If you do cd -P /etc/httpd/logs
, with -P meaning 'physical', you can see that cd
sets PWD to /var/log/httpd.
(sorry, my answer was a mix of your question and jscotts question)