Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm going through some programming tutorials and for every session, I have to start up at least 3 terminal windows (one for a log file tail, one for testing output, one for running various shell commands in, etc.)

Right now I start them all up manually: click the Terminal icon, cd to the right folder, type in the commands, and change the window title to something meaningful.

Is there a way to write up a script or something that would automate that for me? And if so, how?

(I'm cool with not getting a complete script as an answer. A pointer where to start reading would work too.)

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

Since you're clicking the Terminal icon, I assume you're using gnome-terminal.

I got a list of options by using gnome-terminal --help at the command line and reading from there.

Building on maco's answer, I might suggest something like this:

gnome-terminal --window --title=Log -e "tail -f /var/log/syslog" --window --title=Output --working-directory=output --window --active --title=Dev --working-directory=dev/project

This example starts three windows (though you could pass --tab for tabs) and sets the working directories (relative to home) and titles for each, starts the tail command in one and makes the third window active.

Of course you may prefer to use separate lines to launch each window, particularly if you have many arguments.

Another useful thing to do, once you have your windows arranged to your liking, is to use

gnome-terminal --save-config=FILE

This creates a configuration file with information on all open terminal windows and tabs (including the titles, working directories, and so forth). Launching gnome-terminal with the --load-config option will then recreate your layout.

A lot of developers who work with multiple terminals like to use Terminator as it adds features such as a grid layout and keyboard shortcuts.

share|improve this answer
    
Will doing it this way with the -e flag cause the window to close as soon as the command is executed? And if so, is it possible to cause the window to stay open? –  e.m.fields Oct 1 '10 at 18:50
add comment

Whatever terminal emulator you're using should be able to accept a command as an argument. For example:

gnome-terminal -e "tail -f /var/log/syslog"

Just add such commands to your autostart in System -> Preferences -> Sessions (Ubuntu) or System Settings -> Autostart (Kubuntu)

share|improve this answer
add comment

You could also automate that using a script. I recommend reading the Advanced Bash Scripting Guide or the Bash Programming HOWTO, along with the man page for whichever terminal you're using.

Here's a simple example: $ vi your-script

#!/bin/bash
gnome-terminal -e "tail -f /var/log/syslog"
gnome-terminal --working-directory=/foo/bar
gnome-terminal --whatever-else

Then just make it executable: $ chmod +x your-script

share|improve this answer
    
don't you need to exec all those? –  maco Aug 18 '10 at 5:04
    
Yes, unless gnome-terminal is already running, then the command just opens a new window for the other running process and then closes. –  Source Lab Aug 18 '10 at 5:22
add comment

Your Answer

 
discard

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.