How to change gnome-terminal scrollback lines from command line
Using Ubuntu 22.04. I want to change
gnome-terminal scrollback lines from the command line.
I know it’s possible to do it from Terminal -> Settings (the hamburger button) -> Preference -> Profiles -> Unnamed -> Scrolling, like this:
I want to be able to do the same, but from the command line. I am looking for a solution that will work in sync with the GUI option, not overwride it. The idea is that if after some time I forget I set the option from CLI , I should be able to change its value from Preference -> Profiles -> Unnamed -> Scrolling.
This can be done with
Limit scrollback to 250,000 lines:
gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:$(gsettings get org.gnome.Terminal.ProfilesList default | tr -d ')/ scrollback-lines 250000
scrollback-lines value is
2147483647, and the default is
Enable unlimited scrollback:
gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:$(gsettings get org.gnome.Terminal.ProfilesList default | tr -d ')/ scrollback-unlimited true
How it works:
gsettings offers a simple commandline interface to GSettings. It lets
you get, set or monitor an individual key for changes.
The SCHEMA and KEY arguments are required for most commands to specify
the schema id and the name of the key to operate on. The schema id may
optionally have a :PATH suffix. Specifying the path is only needed if
the schema does not have a fixed path.
When setting a key, you also need specify a VALUE The format for the
value is that of a serialized GVariant, so e.g. a string must include
explicit quotes: "’foo’". This format is also used when printing out
We are using
:PATH we need is
[target-profile-id] is the id of the profile we are editing. The command
gsettings get org.gnome.Terminal.ProfilesList default gets the id of the default profile and
tr -d ' removes the
' from the response.
To change terminal scrollback lines, the
scrollback-lines and we set its
250000, which is the number of lines we want to be able to scroll back. Depending on whether we want to enable or disable the unlimited scrollback, we use
If you are worried about resource usage, check this post: Gnome terminal scrollback lines?