Use of gnome-terminal in Ubuntu

Basic use

The gnome-terminal command is used to open a new terminal. You can open a new terminal directly on the command line.

gnome-terminal

Automatically maximize after opening

gnome-terminal --maximize

Full screen after opening

gnome-terminal --full-screen

Set title

gnome-terminal --title="new title"

Open multiple terminals and multiple tabs

gnome-terminal --window --window #打开两个
gnome-terminal --window --tab --window --tab --tab #打开两个,第一个两个tab,第二个3个tab

Set the opening position and size (width x height + left offset + top offset)

gnome-terminal --geometry=80x25+10+10

 Specify the terminal's working directory

gnome-terminal --working-directory=/home/roo/桌面

 Terminal zoom –zoom

gnome-terminal --working-directory=/home/roo/桌面  --zoom=2
gnome-terminal --working-directory=/home/roo/桌面  --zoom=1.5
gnome-terminal --working-directory=/home/roo/桌面  --zoom=0.5

Automatically execute commands after startup

There are two parameters to achieve this function, -e and -x. The difference between these two parameters is:

  • -e can appear multiple times. If it is in front of all --windows, it means it will work on all windows and tabs. If it is after --window or --tab, it means it will only be executed for this tab. Note that -e can only be followed by A parameter, that is to say, if there are spaces, quotation marks are required. See the example below for details.
  • -x can only appear once. Everything after -x is considered to be a command to be executed, so spaces can appear. These commands are executed for all tabs.

for example:

gnome-terminal -e ls
gnome-terminal -x ls

The execution results of these two are the same, that is, the new terminal flashes and disappears. There are several methods:
one is to modify the terminal configuration, right-click on the terminal, select Profiles->Profile Preferences, and then find Title and Command. There is an item in When command exits, and then select Hold the terminal open, and then you can

The second is to redirect the results to less, so that less will not exit before it is executed.

gnome-terminal -x ls|less

The third method is to enable another bash inside bash

gnome-terminal -x bash -c "ls; exec bash"
gnome-terminal -e 'bash -c "ls; exec bash"'

Note that the last command is exec bash. If you write bash directly, it is equivalent to opening a subshell. This has the disadvantage that if you directly press the close button, it will prompt that there are still programs running. It should be noted that, here, execute command, before calling .bashrc, all configurations of all .bashrc are invalid. If you need to use the contents of .bashrc, there is a workaround. Add a sentence at the end of .bashrc

--------------------.bashrc--------------------
其他内容
#最后加上这句
evel "$RUN_AFTER_BASHRC"
-----------------------------------------------

Then when writing the command, modify the RUN_AFTER_BASHRC variable to have .bashrc call this command.

gnome-terminal -x bash -c 'export RUN_AFTER_BASHRC="ls --help"; exec bash'

Or the following writing method is relatively simple (note that it will take effect on all tabs), and it will not be closed automatically.

RUN_AFTER_BASHRC="ls" gnome-terminal

example:

gnome-terminal --title="bot1" -e 'bash -c "docker exec -it bot1 /bin/bash; exec bash"'  --window --tab --tab --tab --tab --tab  --geometry=100x25+10+10

Guess you like

Origin blog.csdn.net/qq_34761779/article/details/130612660