linux - tcsh:ls vs pwd vs cd

标签 linux symlink ls tcsh

我想在 tcsh 中映射文件结构。 给定的是结构 1,只有物理文件夹,比如:

/map/peter/paul/mary

结构 2 仅包含物理文件夹,但最后一个目录,这是结构 1 的“mary”的符号链接(symbolic link):

/map/horse/dog/mouse   ;   mouse -> ../../peter/paul/mary

如果我更改为 /map/horse/dog/mouse 并且输入 pwd,它会告诉我

/map/horse/dog/mouse

如果我在 /map/horse/dog/mouse 中并且如果我制作了一个 cd ..,我就在

/map/horse/dog

但是如果我在 /map/horse/dog/mouse 中并且如果我执行 ls ..,它会告诉我 mary ,但不是鼠标

我明白cd会记住之前的工作目录dog并且cd ..变回dog,虽然 ls .. 解析符号链接(symbolic link)并向我展示 mary,但我希望 ls .. 向我展示 mouse .

以同样的方式,我希望 ls ../.. 向我展示 dog

我发现的所有用例都是关于解析符号链接(symbolic link)和显示物理路径的。但就我而言,对于“ls”,我只需要一种方法来接收未解析的路径。

因此,在“/horse/dog/mouse”中并生成“ls ..”,我想看到“mouse”,而不是“mary”。

将“mouse”设为物理文件夹并将“mary”设为“mouse”的符号链接(symbolic link)不是一个选项,因为“mary”存在于“mouse”之前。

感谢任何解决我问题的帮助/想法。

最佳答案

是的,默认行为是不一致的。您可以使用 symlinks 设置来控制其中的一些;例如:

set symlinks=chase

将使 tcsh 在使用 cd 后进入“真实”目录,这就是你想要的(我认为)。

还有 expandignore 设置。引用 tcsh(1):

   symlinks (+)
           Can be set to several different values to control symbolic link
           (`symlink') resolution:

           If  set to `chase', whenever the current directory changes to a
           directory containing a symbolic link, it  is  expanded  to  the
           real name of the directory to which the link points.  This does
           not work for the user's home directory; this is a bug.

           If set to `ignore', the shell  tries  to  construct  a  current
           directory relative to the current directory before the link was
           crossed.  This means that cding through  a  symbolic  link  and
           then  `cd  ..'ing  returns one to the original directory.  This
           affects only builtin commands and filename completion.

           If set to `expand', the shell tries to fix  symbolic  links  by
           actually  expanding arguments which look like path names.  This
           affects any command, not just  builtins.   Unfortunately,  this
           does  not  work  for hard-to-recognize filenames, such as those
           embedded in command options.  Expansion  may  be  prevented  by
           quoting.  While this setting is usually the most convenient, it
           is sometimes misleading and sometimes confusing when  it  fails
           to  recognize  an argument which should be expanded.  A compro‐
           mise is to use `ignore' and use the editor  command  normalize-
           path (bound by default to ^X-n) when necessary.

关于linux - tcsh:ls vs pwd vs cd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39342889/

相关文章:

bash - ls:将名称模式的文件grep成一行

linux - 如何从命令任务传递加密密码以执行脚本以调用 pmrep

linux - centos 6.4 命令行问题?

windows - 如何通过 Cygwin 使用 Windows git 创建的符号链接(symbolic link)

git - 设置 GIT_DISCOVERY_ACROSS_FILESYSTEM 以允许服务访问存储在符号链接(symbolic link)下的 git repo

arrays - 如何在 Linux Bash 中将 ls 分配给数组?

python - python-magic 使用了哪个 libmagic?

linux - '/usr/lib/mozilla/plugins/npPluginTest.so' 不是 sh 的 ELF 可执行文件

JAVA如何找到符号链接(symbolic link)指向的目标文件路径?

linux - 使用 'ls' 与选项和文件夹并获取完整路径