简体   繁体   中英

tcsh: ls vs pwd vs cd

I want to make a mapping of file structures in tcsh. Given is structure 1, with physical folders only, say:

/map/peter/paul/mary

Structure 2 contains physical folders only, but the last directory, this is a symlink to "mary" of structure 1:

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

If I change to /map/horse/dog/mouse and if I make a pwd , it tells me

/map/horse/dog/mouse

If I am in /map/horse/dog/mouse and if I make a cd .. , I am in

/map/horse/dog

but if I am in /map/horse/dog/mouse and if I do a ls .. , it tells me mary , but not mouse .

I understand that cd remembers the previous working directory dog and cd .. changes back to dog , while ls .. resolves the symlink and shows me mary , BUT I want ls .. to show me mouse .

In the same way I want ls ../.. to show me dog .

All the use cases I found are about resolving symlinks and showing the physical path. But in my case, for "ls", I need a way to receive the unresolved path, only.

So, being in "/horse/dog/mouse" and making a "ls ..", I want to see "mouse", but not "mary".

Making "mouse" the physical folder and "mary" the symlink to "mouse" is not an option, because "mary" exists before "mouse".

Any help/ ideas to solve my problem is appreciated.

Yeah, the default behaviour is inconsistent. You can control some of it with the symlinks setting; for example:

set symlinks=chase

Will make tcsh go to the "real" directory after using cd , which is what you want (I think).

There's also the expand and ignore settings. Quoting 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM