.!cd <new_dir>

Is there a way to change the current unix directory so that full path filenames needn’t be
specified, for instance in TFile instantiation? I would have expected the shell command

.!cd <new_dir>

to work, but it doesn’t (tried linux RH7 & Fedora)


It is as simple as

root [0] .cd <new_dir>

or for pure cint,

cint> cd <new_dir>

Don’t use ‘!’ command because ‘cd’ is given to new shell only and result does not remain in orignial process.

Thank you
Masa Goto


For ROOT, you can also use gSystem->cd(const char* path) function, instead of .cd command.

root[0] gSystem->cd("/your/path")

Thank you
Masa Goto

Hello users of cint.

I am having the same problem using pure cint. Changing the directory with for example

cint> cd /home/username

does not work at all. Cint does not prompt an error and executing pwd echos the directory I started cint. The hints Masaharu gave did not work for me. Does anyone know why cint is behaving like this?

Thanks in advance

Jupp Tscheak

uname -a: Linux kubuntu 2.6.31-15-generic #50-Ubuntu i686 GNU/Linux

[quote] Does anyone know why cint is behaving like this? [/quote]Yes, doing cint> .! cd /home/username[code]is intentionally behaving in a way similar to the following shell commands:[code] $ sh -c "cd somewhere"i.e the ‘cd’ is execute in a sub-shell and has no effect on your current shell.

The only way to do what you need is to call the function (declared in unistd.h) chdir (which is what gSystem->cd does). However we do not provide a dictionary for chdir by default, so you will need to either generate a dictionary for it or call it from one of your compiled functions.


Thanks for your answer pcanal. I understand what you mean but I did not execute “cd” in a new shell using “.!”. I did it like

cint> cd /home/username and not

All other commands like “ls” or “pwd” do work. Why is only "cd " not working?

Best regards

Hello experts,

why is it not possible to make gSystem change the directory with a pre-defined const char* as argument?



Sorry, let me be more verbose here:

I wonder why I can’t successfully change directories by using a pre-defined path (const char*):

root [0] const char* dir = gSystem->pwd()
root[1] gSystem->ChangeDirectory(“somewhere/else”)
Bool_t 1
root[2] gSystem->ChangeDirectory(dir)
Bool_t 0

I hope, the answer is trivial… :confused:



// you MUST create your “private” copy of the “gSystem->WorkingDirectory()” contents
TString dir1(gSystem->WorkingDirectory())
// in other cases, you can simply do:
const char *dir2 = "/tmp"


thanks a lot, the first version works. The second one does not, but ok…

Thanks again!


It seems to work for me with ROOT 5.28 and 5.30 (Ubuntu 10.04.3 LTS. i686, gcc 4.4.3).
If it does not work for you, I think it might be a bug in your ROOT which you should report.