Saturday, 15 February 2014

linux - Why can't I work with files in ".." from within a symbolic link? -



linux - Why can't I work with files in ".." from within a symbolic link? -

i have next directory structure:

misha@misha-lmd:~/tmp$ ls -l total 4.0k -rw-r--r-- 1 misha lmd 21 feb 18 21:00 hello.py lrwxrwxrwx 1 misha lmd 20 feb 18 21:01 symlink -> /home/misha/nobackup/

next, seek following:

misha@misha-lmd:~/tmp$ cd symlink misha@misha-lmd:~/tmp/symlink$ cat ../hello.py cat: ../hello.py: no such file or directory

why doesn't work?

if instead:

misha@misha-lmd:~/tmp/symlink$ cd .. misha@misha-lmd:~/tmp$ cat hello.py print "hello world!"

then well. cd handles .. properly, cat doesn't. sorcery, , how create things work way want them to?

edit

ok, of answers here, i've found out bit more what's going on. first, cd not executable, built-in command of shell (in case, bash):

misha@misha-lmd:~/tmp$ type cd cd shell builtin

if man bash, can find environment variables bash uses housekeeping, including moving around directories. there other built-ins, pwd, have counterparts executables:

misha@misha-lmd:~/tmp/symlink$ type pwd pwd shell builtin misha@misha-lmd:~/tmp/symlink$ /bin/pwd /home/misha/nobackup misha@misha-lmd:~/tmp/symlink$ /bin/pwd -l /home/misha/tmp/symlink

the /bin/pwd executable prints physical path default, can print logical path given `-l' switch. similarly, when seek do:

misha@misha-lmd:~/tmp/symlink$ cat ../hello.py cat: ../hello.py: no such file or directory

things failing because .. beingness interpreted physical parent directory, not logical one. allows me refine question as:

when specify command-line argument executable, how can .. mean logical parent, not physical one?

because directory .. in symlinked directory home directory.

../something means "go .. directory", not "strip lastly path component".

you can seek pwd -p see are, after alter symlink.

linux bash command-line

No comments:

Post a Comment