Linux Commands Examples

A great documentation place for Linux commands

gnome-terminal

is a terminal emulation application.

Synopsis

gnome-terminal [-e, --command=STRING] [-x, --execute ] [--window-with-profile=PROFILENAME] [--tab-with-profile=PROFILENAME] [--window-with-profile-internal-id=PROFILEID] [--tab-with-profile-internal-id=PROFILEID] [--role=ROLE] [--show-menubar] [--hide-menubar] [--geometry=GEOMETRY] [--disable-factory] [-t, --title=TITLE] [--working-directory=DIRNAME] [--usage] [-?, --help]


add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!

examples

12
source
            
gnome-terminal --command "/home/rush/rfid.py"
6
source
            
gnome-terminal -e "gdb ./simplefrac"
2
source

How can I turn off font-antialiasing only for gnome-terminal, but not for other applications?

Not sure if this actually works, but you could try to use .Xdefaults to configure this. Make a file named .Xdefaults in your home dir. Put in the following:

Xft*antialias: false

Effects everything!!! Just find the right name, and it should work.

1
source
            
gnome-terminal -e "./simplefrac"
0
source

Slight delay when switching modes in vim using tmux or screen

It sounds like you are using a mapping that starts with ESC. When you press the ESC, vim has to wait to see if the next key is the one in the mapping. If it is not, it can immediately continue.

The vim configuration can be terminal dependent, so the fact that it does not happen outside of tmux does not mean much. Vim can query the $TERM environment variable and choose different configuration depending on its value.

Since gnome-terminal uses, AFAIK, xterm as the value of the $TERM variable, and tmux uses screen, I would look through all your vim configuration files for settings that are only used is the $TERM variable is equal to screen. My guess is that some vim config file on your system sets mappings for handling of arrow keys (those start with the ESC character) when the terminal is screen.

You can test it by temporarily changing the $TERM variable in tmux before starting vim. If your shell is bash, call vim as

TERM=xterm vim

in tmux and see if the problem persists. You sould not use that as a fix, though, since there may be differences between the terminal capabilities of tmux and xterm, and you may run into some problems.

0
source

Save multiple gnome-terminal layout?

You can create profiles for Gnome-Terminal from the Edit Profiles dialog under the Edit menu. To start Gnome-Terminal with a certain profile, you'd do this:

gnome-terminal --window-with-profile=<profile_name>

Naturally, you can configure different launcher icons to automatically launch different profiles, or you could include lines in an X-session startup script to start several different terminals, each with a different profile, when you login. Various options can be combined in a launcher icon to give you one specific terminal type, and you could create as many launchers as you need different terminal types.

Other commandline options might be useful to get exactly the effect you want, if the profile mechanism isn't fine-grained enough for you. See man gnome-terminal on your system for full details, but here are some suggestions from this Ubuntu forum discussion:

# define a terminal 100 columns by 20 lines
--geometry=100x20

# set the titlebar
--title=irssi

# run a particular program
--execute irssi
0
source

How to show output on terminal and save to a file at the same time?

Use tee.

user@unknown:~$ sudo command -option | tee log
0
source

How to run programs from a linux terminal without blocking the terminal?

You are looking for job control which is supported by most shells. See this article for an introduction. At some point you might also want to read the official documentation for bash which is the default shell in Ubuntu.

In short: To start a job automatically in the background put an & after the program call

$ program &

You can also stop programs with CTRLz and then put them into the background later with bg

$ program
^Z
$ bg

To get them to run in the foreground again use fg.

0
source

Programmatically open tab in gnome-terminal, execute command, and have tab stay open

If you have xdotool and wmctrl installed, then the following shell script might work:

#!/usr/bin/env bash

window="$(xdotool search --class gnome-terminal | head -1)"
xdotool windowfocus $window
xdotool key ctrl+shift+t
xdotool type "$*"
xdotool key Return

I use it like this:

$ run-in-new-tab 'ls -l'

I found this idea on Trustin Lee's blog.

0
source

In vim, how can I quickly switch between tabs?

(Unfortunately) vim also uses CtrlPgDn/PgUp to cycle through tabs. You'll need to use map to map tabn/tabp to something usable.

0
source

indistinguishable active tab in gnome terminal

gnome-terminal-3.x uses Gtk+3, so changing the Gtk+2 theme indeed does not change the look of your gnome-terminal. There's no Gtk+3 theme switcher except for the Gnome3 tool yet afaik, so you're probably pretty much stuck with the look of it. An alternative would be downgrading to gnome-terminal-2.x.

0
source

Can I have my terminal background change based on hostname?

It does not seem that there is any functionality in gnome-terminal to add a new tab to an existing window from the command-line. But there are a few options to accomplish what you want.

Per Command Profiles

Create a new gnome-terminal profile for each host you will SSH into. If you only have a few hosts that you regularly connect to, this might be the simplest. Each profile can have a different title, foreground color, background color, custom command and other settings defined. Then you can use File -> Open Tab to open a new tab with the selected profile.

Reuseable Profile

Create a new gnome-terminal profile that will be used to open a new window each time you want to connect to a different SSH host (based on this AskUbuntu answer that Stefano pointed out). This would work good if you connect to many different hosts frequently. This will not allow you to distinguish between different gnome-terminal windows where you are connected to different hosts solely on the background/foreground colors, but you will have a different title per window.

  1. Create a new gnome-terminal profile (File -> New Profile) based on the Default profile and call it "RemoteHost" (note, no spaces in "RemoteHost" to make commands easier).
  2. Under the Title and Command tab, change:
    1. Initial title: to "Remote Host"
    2. When terminal commands set their own titles: to Replace initial title
  3. Under the Colors tab, change:
    1. Uncheck Use colors from system theme
    2. Build-in schemes: to Custom
    3. Text color: and Background color: to colors of your choosing. Keep in mind that some commands (like ls) use colors for their output and you don't want to pick colors that will make it difficult to read the output.
  4. Click on the Close button to save your new profile.
  5. Now you can open a new gnome-terminal window for each remote SSH host using the command gnome-terminal --window-with-profile=RemoteHost -t "Some Remote SSH Host" -x ssh user@somehost. The -t option sets the gnome-terminal window title and the -x option executes the rest of the command line in the terminal. You could even make an alias to shorten total keystrokes.

Command-Line

I found this blog entry with the following script that uses the xdotool and wmctrl commands (they weren't installed by default on Ubuntu, so you might need to install them first) to use the gnome-terminal Ctrl + Shift + t keyboard shortcut to open a new tab in the current gnome-terminal window. It could be modified to open a new tab with a specific profile and execute some command for you.

#!/bin/bash
# Path: /usr/local/bin/gnome-terminal
if [ "x$*" != "x" ]; then
  /usr/bin/gnome-terminal "$@"
else
  pgrep -u "$USER" gnome-terminal | grep -qv "$$"
  if [ "$?" == "0" ]; then
    WID=`xdotool search --class "gnome-terminal" | head -1`
    xdotool windowfocus $WID
    xdotool key ctrl+shift+t
    wmctrl -i -a $WID
  else
    /usr/bin/gnome-terminal
  fi
fi

Other

You could get creative and try some other things.

This SuperUser answer basically uses a bit of "script-fu" acrobats to create a temporary gnome-terminal profile that is used to open a new window. It may be modified for your use.

You could probably use this StackOverflow Q&A and more "script-fu" acrobats to dynamically change the gnome-terminal title whenever you SSH to a remote host. It would not be as prominent as background/foreground color changes, but it would be better than a standard Terminal title all the time.

0
source

How do I detect when I a terminal gets focus in Linux?

I expect you'll have to listen in on the X-window messages for the appropriate FOCUS message. Not sure how easy/difficult that will be though.

Alternatively How to know which window has focus and how to change it? talks about determining the window with focus and provides a couple of options: you could use that technique and just run it in a loop and track the focus changes.

0
source

can I make ubuntu's terminal program automatically copy to the clipboard selected text and paste on right click?

A little known feature of the X server in Linux and other UNIX-like operating systems gets you half of the way there.

Anything you highlight in Linux, regardless of the program, is put into a special clipboard buffer, which you can paste using your mouse's middle (wheel) button (which is emulated on many laptops by pushing both buttons at the same time). You can also use a keyboard shortcut, if you like.

Unfortunately, I don't think you can change gnome-terminal's right-click behavior.

0
source

Is there any way to keep text passed to head, tail, less, etc. to be colored?

I presume you are piping from ls and want to preserve the terminal color codes. You can say ls --color=always (instead of the default of --color=auto), which will preserve the codes, but that won't guarantee that the thing you're piping to knows how to understand them.

If you use glark instead of grep it will try to display with colors.

If you use less with -R it will attempt to display with colors.

0
source

gnome-terminal: how to preserve symlinks of working directory when opening new tab?

I suspect there is no truly good answer to this. gnome-terminal finds bash's current working directory by inspecting /proc/<pid>/cwd, which has the symlinks expanded (probably for security reasons, if nothing else). I don't know of another way for one process to find another process's working directory.

As a workaround, there are some bash tricks you could try, but see the WARNING below! In .bashrc:

...
PROMPT_COMMAND='pwd >~/.bashlocal_saved_dir'
...

[ -n "$PS1" -a -f ~/.bashlocal_saved_dir ] && cd `cat ~/.bashlocal_saved_dir`
# end of .bashrc

This will do two things. First, every time bash displays the prompt, it will first write its current working directory into the file .bashlocal_saved_dir in your home directory. Second, when bash starts interactively (as opposed to running a script), it will change to the directory stored in that same file. This means that when you start a new interactive bash, it will start in the same dir as the bash that last displayed its prompt. Note that you can hit Enter to cause a bash to redisplay its prompt, thus making it the last. :)

WARNING: This is a hack, and I have only tried it up to the point that I know it works. Think bubble gum and shoestrings. It may have surprising effects, and will certainly not work as cleanly as gnome-terminal's approach. In particular, if you're running a lot of tabs at once, all doing background tasks, you may very well end up in the "wrong" directory when opening a new tab.

0
source

gnome-terminal/bash: How to cancel inserted commands that will be executed later?

Type Ctrl+Z (goes back to prompt, doesn't execute keyboard buffer) and then fg to get the running execute_some_long_command back on track.

At least that worked in my Fedora 14 gnome-terminal, testing with sleep 20 as execute_some_long_command and echo blah as the typed garbage.

description

GNOME Terminal is a terminal emulation application that you can use to perform the following actions:

Access a UNIX shell in the GNOME environment.

A shell is a program that interprets and executes the commands that you type at a command line prompt. When you start GNOME Terminal, the application starts the default shell that is specified in your system account. You can switch to a different shell at any time.

Run any application that is designed to run on VT102, VT220, and xterm terminals.

GNOME Terminal emulates the xterm program developed by the X Consortium. In turn, the xterm program emulates the DEC VT102 terminal and also supports the DEC VT220 escape sequences. An escape sequence is a series of characters that starts with the Esc character.

GNOME Terminal accepts all of the escape sequences that the VT102 and VT220 terminals use for functions such as positioning the cursor and clearing the screen.

options

-e, --command=STRING

Execute the argument to this option inside the terminal.

-x, --execute

Execute the remainder of the command line inside the terminal.

--window-with-profile=PROFILENAME

Open a new window containing a tab with the given profile. More than one of these options can be provided.

--tab-with-profile=PROFILENAME

Open a tab in the window with the given profile. More than one of these options can be provided, to open several tabs .

--window-with-profile-internal-id=PROFILEID

Open a new window containing a tab with the given profile ID. Used internally to save sessions.

--tab-with-profile-internal-id=PROFILEID

Open a tab in the window with the given profile ID. Used internally to save sessions.

--role=ROLE

Set the role for the last-specified window; applies to only one window; can be specified once for each window you create from the command line.

--show-menubar

Turn on the menu bar for the last-specified window; applies to only one window; can be specified once for each window you create from the command line.

--hide-menubar

Turn off the menu bar for the last-specified window; applies to only one window; can be specified once for each window you create from the command line.

--geometry=GEOMETRY

X geometry specification (see "X" man page), can be specified once per window to be opened.

--disable-factory

Do not register with the activation name server, do not re-use an active terminal.

-t, --title=TITLE

Set the terminal’s title to TITLE.

--working-directory=DIRNAME

Set the terminal’s working directory to DIRNAME.

--usage

Display brief usage message.

-?, --help

Show help message.


author

This manual page was written by Christian Marillat marillat[:at:]debian[:dot:]org for the Debian GNU/Linux system (but may be used by others).

How can this site be more helpful to YOU ?


give  feedback