Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've typically have gnome-terminal open with ~8 tabs, using 2 consecutive tabs for the same task (one has emacs, the other is used to do git checkins and unittest runs and so).

When changing tasks, I need to move to a new directory - in both tabs. How can I change the work directory of the second tab to the one of the first tab, with as few steps as possible? Preferably keyboard only.

share|improve this question
Do you mean to say that if you are in Tab-1 with /tmp as CWD and in Tab-2 with /mnt as CWD, then whenever you cd to ~ in TAB-1 then at the same time, TAB-2 MUST get changed to ~ ?? – SHW Jun 18 '12 at 8:24
No, just when I say that I want to change now. Such as a command "change cwd to cwd of tab1". – cweiske Jun 18 '12 at 8:28
up vote 4 down vote accepted

Here is a work-around: on one tab, record the CWD into a temp file, on the other tabs, cd to the just-saved dir. I would put these two aliases to my .bashrc or .bash_profile:

alias ds='pwd > /tmp/cwd'
alias dr='cd "$(</tmp/cwd)"'

the ds (dir save) command marks the CWD, and the dr (dir recall) command cd to it. You can do something similar for C-shell.

share|improve this answer
This is the simplest solution, and it's the one that will work everywhere - if I'm using gnome terminal or the VTs on alt+1-6. I'll use this. Thanks all others, too – cweiske Jun 19 '12 at 8:07

Try the terminal emulator terminator. You can open multiple shells and use the "Broadcast All" feature to send the same command to all of them.

share|improve this answer

What you are looking for, can be achieved by writing a shell script with the help of


Example script that you can use:

xdotool type "cd $1
xdotool key Ctrl+Next
xdotool type "cd $1
share|improve this answer
As gnome-terminal doesn't have support for D-Bus or any other interface there is no elegant way to do this. – pbm Jun 18 '12 at 21:30

In zsh, you can do the following:

  1. Run a command in a shell.
  2. Run fc -AI in that shell.
  3. Run fc -RI in another shell.
  4. Run !! or press Up then Enter in the second shell to recall the last command executed in the first shell.

fc -AI writes out the command history of the first shell, and fc -RI reads it back into the second shell. If you turn on the inc_append_history, then the equivalent of fc -AI is performed automatically after each command.

If you turn on the share_history option, then all history lines are automatically shared between all shell instances, so you can go straight from step 1 to step 4. This can feel invasive.

If you used a relative path to change the directory, you'll need to obtain an absolute path first. One way to do that is to type cd $PWD (or just $PWD if you have the auto_cd option turned on) and press Tab (or C-x * with some completion settings) to expand $PWD then press Enter.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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