Linux run command new terminal

Command to open new terminal window from the current terminal?

I installed xdotool by running sudo apt-get install xdotool and throw xdotool key ctrl+alt+t command to open a new terminal window from the current one.But it was not working. What was the command to open a new terminal window from the current gnome-terminal?

3 Answers 3

Just this command will do:

Normally if you want a command to open from the terminal and separate (so it returns to the prompt without having to close the opened program), you have to use something like this:

However the parent terminal seems to detect that the same command is being used so you don’t need to do that and gnome-terminal will suffice. This also seems to happen when running xfce4-terminal from Xfce’s terminal, konsole from KDE’s as well (doesn’t seem to work when running xterm from xterm (see also xterm xterm ) — Running konsole from Gnome/Unity & Xfce’s terminal works as well, but for Xfce’s terminal in gnome terminal you need xfce4-terminal & disown ).

 gnome-terminal [-e, --command=STRING] [-x, --execute ] [--window-with-profile=PROFILENAME] [--tab-with-profile=PRO‐ FILENAME] [--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-direc‐ tory=DIRNAME] [--usage] [-?, --help] 

You probably want to run it in the background, like that: gnome-terminal & . Otherwise the current terminal will be unusable, as it will be busy running that other one — so you end up with just one usable terminal, which may be missing the point.

Interesting. You are apparently right, however, I am not wrong neither 🙂 I’ve just checked that in details. If I run gnome-terminal while another instance of it is already running (it may be the one I’m using to launch this command) — it indeed finishes immediately, because instead of running a new instance gnome-terminal , it tells that currently running one to open a new window. Tricky. But if I run gnome-terminal from anything else, and there are no other instances of gnome-terminal running, it does as I explained in the previous comment, blocking the terminal used to launch it.

@RafałCieślak — anyway, konsole doesn’t seem to need at all. weird. I have no idea why this question/answer is so popular 🙂

Thanks very much, if you want to open a terminal with the same directory you could do this, gnome-terminal .

Command to open new terminal window from the current terminal,

sudo apt-get install xdotool 

I don’t see any reason to use xdotool key ctrl+shift+n while using gnome-terminal you have many other options; see man gnome-terminal in this sense.

Still think this neat 🙂 is there any equivalent for Mir or Wayland (for implementations not compatible with X server stuff)

The following script will open a new tab in the current gnome-terminal window and optionally give that tab a title. This works from any window, you don’t have to be in a gnome-terminal window to run it. And, if there is no gnome-terminal running, it will start one. The only caveat is that if you changed the hotkey for opening a new tab you might have to change the line xdotool key ctrl+T to use your hotkey instead.

#!/bin/bash DELAY=1 # get title we are going to set tab too, default to Terminal title="Terminal" if [ $# -eq 1 ]; then title="$1" fi # get pid of running terminal server TPID=$(ps -C gnome-terminal-server -o pid | tail -1 | sed -e's/\s//g') if [ $ == "PID" ]; then # no terminal process running yet, so just start one gnome-terminal -t "$title" --tab exit 0 fi # there is a terminal, get window id of the running terminal server WID=$(wmctrl -lp | awk -v pid=$TPID '$3==pid') # get title of currently active tab TTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk ''` if [ "$TTITLE" == "\"Terminal\"" ]; then # so we don't go into an infinite loop later TTITLE="we had a terminal named terminal $$" fi # get focus on active terminal tab xdotool windowfocus $WID # use keyboard shortcut to open new tab xdotool key ctrl+T # see if we have created tab and are in terminal NTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk ''` waited=0 while [ "$TTITLE" == "$NTITLE" ]; do # sleep for 1 second before we try again xdotool sleep 1 NTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk ''` if [ $waited == 0 ]; then echo "Waiting " waited=1 fi echo -n "." done if [ $waited == 1 ]; then echo "" fi # active tab is the new one we created, wait DELAY seconds just to be sure we can type into it to set tab name xdotool sleep $DELAY xdotool type --clearmodifiers "termtitle $title" xdotool key Return # make tab the active window and raise it to top wmctrl -i -a $WID exit 0 

Источник

Читайте также:  Postgresql бэкап базы данных linux

Execute a command in a new terminal window

I’m on ubuntu 17.04, and I’m trying to execute some commands in sequence, so I have written this shell script:

#! sudo java -jar ~/Desktop/PlugtestServer.jar sudo /opt/lampp/lampp start sudo node httpServer.js 

The problem is that after the first command, it execute PlugtestServer and then stop on it, because it is a server and continue to execute it. There is a command in order to automatically open a new terminal and execute PlutestServer in it?

2 Answers 2

There is way to open a new terminal window and execute command in it using gnome-terminal The sample format for command is:

gnome-terminal -e "command you want to execute" gnome-terminal -e "./your-script.sh arg1 arg2" 

Your script stays on the first command showing output, you can make the shell move on by adding «&» to the end of your lines. However this might still not do what you want, if you want PlugTestServer to remain running when you log out. For that you should include «nohup» which will keep the command running while piping output to a file. So, an example:

#!/bin/sh nohup java -jar ~/Desktop/PlugtestServer.jar > plugtest.out & #Pipes output to plugtest.out, use /dev/null if you don't care about output. /opt/lampp/lampp start node httpServer.js 

Notice I removed sudo from the script. It’s generally better to invoke the script with «sudo» unless you have specific reason to, at the very least it simplifies the commands.

I’m not sure if your second and third command «fork» or «block», so add «nohup» and «&» if you need to.

Источник

Run command on another(new) terminal window

How to run any command in another terminal window? Example: I opened one terminal window and if I run command like apropos editor , then it run and out-puts on that window. But I want to run same command on another terminal window (new window) instead on present window from first terminal. Further clarification:
I need suggest-command that open new terminal window and run mentioned in that (newly opened) window. (where suggest-command is example of suggestion of command.) How to do that?

Читайте также:  Linux set serial port

While opening a new terminal may solve your problem, you might also wish to simply use nohup, re-direct the output, and put your editor in the background. nohup apropos editor &> /dev/null &

7 Answers 7

This might be what you run:

gnome-terminal -- sh -c "bash -c \"!!; exec bash\"" 

In older versions, -e and -x were used:

gnome-terminal -e "bash -c \"!!; exec bash\"" # or gnome-terminal -x sh -c "!!; bash" 

It opens gnome-terminal with your last command ( !! ) executed and it stays open with the command output in the shell, even with an interactive command like top or less .

gnome-terminal -- sh -c "bash -c \"apropos editor; exec bash\"" 
gnome-terminal -c "bash -c \"apropos editor; exec bash\"" # or gnome-terminal -x sh -c "apropos editor; bash" 

Under Xubuntu, the terminal command is xfce4-terminal , see it’s documentation for more details: docs.xfce.org/apps/xfce4-terminal/command-line

Each terminal is even a program that you can launch as any other program, with & to put in background, giving a list of arguments and so on.

Which terminal to use it depends first from the availability of the system that you are using (if they are installed or not), after from their peculiarity and then from your personal taste.

 konsole --hold -e "ls" & xterm -hold -e "ls" & gnome-terminal -e "ls" & . 

Note the differences between -hold of xterm and —hold of konsole .

Each realization has different options that you have to check with the help. Even the help can be invoked in different way. You can find that man konsole doesn’t function and so you have to ask directly to the executable with —help .

This is a list of terminal you can search on your system

aterm - AfterStep terminal with transparency support gnome-terminal - default terminal for GNOME guake - A dropdown terminal for GNOME konsole - default terminal for KDE Kuake - a dropdown terminal for KDE mrxvt - Multi-tabbed rxvt clone rxvt - for the X Window System (and, in the form of a Cygwin port, for Windows) rxvt-unicode - rxvt clone with unicode support xfce4-terminal - default terminal for Xfce desktop environment with dropdown support Terminator - is a GPL terminal emulator. It is available on Microsoft Windows, Mac OS X, Linux and other Unix X11 systems. Terminology - enhanced terminal supportive of multimedia and text manipulation for X11 and Linux framebuffer tilda - A drop down terminal wterm - It is a fork of rxvt, designed to be lightweight, but still full of features xterm - default terminal for the X Window System Yakuake - (Yet Another Kuake), a dropdown terminal for KDE 

Источник

Читайте также:  All linux desktop environments

Run a script in a new terminal window

I am looking to run a script that is separate from my parent script in another terminal window while keeping the current window usable. The reasoning behind this is I wish to allow the user to be able to run a watch script that will monitor directory changes as they are made. this is my function for this

However this only continues to run in the current window in the background. I cannot use or install any of the following due to my linux distribution: genone-terminal ; xterm ; screen ; konsole ; terminal or any other installable tools! Any advice would be great as I am just starting out with bash scripting!

This is something that is specific to your terminal emulator. For example, xterm -e /path/to/script . Which terminal emulator are you using? (And what distro?)

@Sparhawk when I echo $TERM it says xterm is currently not installed and to install it. The distro is: Linux Mint 17.3 Rosa

$TERM is not your terminal emulator. (e.g. I get xterm-256color even though I’m running Terminator.) What application are you actually launching to start the emulator? Also, you should be able to install any of those alternatives in Mint.

@Sparhawk the terminal I am using is the /bin/bash terminal but I also have Xfce Terminal. To start the terminal I press ctrl alt + T which brings up the /bin/bash terminal. Also the installing is not the issue unfortunately, its other constraints that are restricting me from installing them.

3 Answers 3

If you just want to watch the output from the script, you can redirect the output from your script to a file and then watch that file in another window:

# Run the script and log all output to a file ./watch.sh &> /var/log/watch.log & # Watch the file, possibly in another terminal window tail -f /var/log/watch.log 

In my experience, this behavior (writing to a log file) is pretty typical. I don’t recall ever having used a command-line application that started spawning other terminal windows.

That said, if you really want to open a new terminal window from the command-line then that will depend on the terminal application. There is a good post about this on the AskUbuntu StackExchange site:

In particular see this answer. For example, for the Gnome terminal you might use a command such as the following:

gnome-terminal -x sh -c "./watch.sh; bash" 

If you want to programmatically determine which terminal application is being used, you might want to refer to the following AskUbuntu post:

The accepted solution there defines the following function:

which_term()< term=$(perl -lpe 's/\0/ /g' \ /proc/$(xdotool getwindowpid $(xdotool getactivewindow))/cmdline) ## Enable extended globbing patterns shopt -s extglob case $term in ## If this terminal is a python or perl program, ## then the emulator's name is likely the second ## part of it */python*|*/perl* ) term=$(basename "$(readlink -f $(echo "$term" | cut -d ' ' -f 2))") version=$(dpkg -l "$term" | awk '/^ii/') ;; ## The special case of gnome-terminal *gnome-terminal-server* ) term="gnome-terminal" ;; ## For other cases, just take the 1st ## field of $term * ) term=$ ;; esac version=$(dpkg -l "$term" | awk '/^ii/') echo "$term $version" > 

Источник

Оцените статью
Adblock
detector