I want to do something similar to what's written here without using zsh (I use bash), but if I try to start screen with

screen 'cd /home/cataldo/Programs'

I get the following error:

Cannot exec 'cd home/cataldo/Programs': No such file or directory

Without qoutes after exec it does not work either. Double quotes make no difference. Using bash -c "cd .." does not work.

It might be some permission problem or screen executes commands as a special user at startup?

Thank you very much for your help!

screen --version
Screen version 4.00.03jw4 (FAU) 2-May-06

cat /etc/debian_version 

It doesn't work because cd is a shell built-in command (try which cd). Screen has a chdir command which you can use to achieve your goal: Put the following inside your .screenrc:

chdir /home/cataldo/Programs

Now start screen and you should be in the specified directory.


screen doesn't know about cd as it is a shell builtin, so screen can't execute it. However, screen has a builtin command of chdir. If you execute chdir by itself from the screen command line, all new windows in the screen session will start in your $HOME. If you execute chdir /home/cataldo/Programs from the screen command line, all new windows in the screen session will start in /home/cataldo/Programs.

If you want to open 3 windows in different directories when you start a new screen session, in your ~/.screenrc define the directory with chdir and then immediately start a new window.

# Start these windows when screen starts up
chdir /home/cataldo/Programs
screen 0
chdir /usr/local/bin
screen 1
chdir /tmp
screen 2

From man 1 screen (pay attention to the last line)

chdir [directory]
Change the current directory of screen to the specified directory or,
if  called  without  an argument,  to your home directory (the value of
the environment variable $HOME).  All windows that are created by means
of the "screen" command from within ".screenrc" or by means of "C-a : 
screen ..." or "C-a c" use this as their default directory.  Without a 
chdir command, this would be the directory from which screen was invoked.  
Hardcopy  and  log  files  are  always written  to  the window's default 
directory, not the current directory of the process running in the window.  
You can use this command multiple times in your .screenrc  to  start  
various windows  in  different default directories, but the last chdir value 
will affect all the windows you create interactively.

What you say doesn't make much sense. Even if cd were a real command, screen would just change directory and then immediately exit, which would do nobody any good whatsoever.

If you only want to start a specific screen session in a particular directory:

(cd home/cataldo/Programs && screen)

That will change directory, start screen with a shell, and return to your existing directory when screen exits.

  • 1
    Thanks for the reply, but I am afraid that it does not make much sense. When I open screen I want to open 3 different subscreens in 3 different subdirectories, as it is shown in the page linked in the question. I think all this should be initialized in .screenrc, not from command line. – Gismo Ranas Mar 30 '12 at 14:50

You can add stuff "cd /home/cataldo/Programs^M" to your ~/.screenrcor at the prompt using C-a :

  • Thanks, I didn't know about stuff. Contrary to chdir it works out of the box in order to start a number of screen windows in different directories from my screen configuration file. – fotNelton May 3 '17 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.