Is there a way to tell screen not to dereference symlinks when one is passed to the chdir command?

In my .screenrc I have commands like this:

chdir /data/project1
screen -t "project1"
chdir /data/project2
screen -t "project2"

The idea being that when I launch screen, I get a few terminals preloaded in a bunch of common directories I use frequently.

Unfortunately everything in /data is a symlink on my system, so when I load screen with the above commands, the terminals are left in different directories, like /mnt/remote/server1/long/path/to/project1 instead of /data/project1. I have to type cd /data/project1 in the terminal to get into the folder I want.

Since the paths I'm using are very long and can change, I prefer getting in the habit of using my /data shortcuts so that I don't have to change any habits if I relocate the files elsewhere.

Is there some way to tell screen that, when using chdir and the target is a symlink, not to dereference the symlink and to just change into that directory anyway?

1 Answer 1


I guess you just misunderstand what happens there.

When you are in


with your shell and type

cd /data/project1

then you do not change the directory. You just change what the shell is showing. The shell tells logical and physical directory hierarchies apart. screen (and more or less everything else) does not.

The easiest solution is probably to add some code to .bashrc (assuming you use bash):

test "$PWD" = '/mnt/remote/server1/long/path/to/project1' && cd /data/project1
  • Interesting, you are right. Running /usr/bin/pwd from /data/project1 does indeed print /mnt/remote/server1.... I was assuming the symlinks were resolved at a much lower level than they actually are!
    – Malvineous
    Oct 7, 2017 at 10:09
  • @Malvineous Symlinks can easily be detected but the default is to just not care about them. There are a few exceptions: shells, find, ls, backup / copy software. Oct 7, 2017 at 10:32
  • Right! Well, after considering piping commands to bash from my .screenrc and bind mounts, I ended up settling on your solution as the cleanest. I used [[ "$PWD" == "$1"* ]] && cd `pwd | sed "s|$1|$2|"` in a function so that I could handle a whole bunch of folders in the same prefix. Thanks!
    – Malvineous
    Oct 7, 2017 at 10:36
  • 1
    @Malvineous You do not even need sed: cd "${PWD/"$1"/"$2"}" Oct 7, 2017 at 10:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .