Small Things for Linux
1. alternatives
manage multi-version softwares
I have a gcc-13
and a gcc-14
in /usr/bin
. Here I use alternatives
to
manage them.
1 | sudo update-alternatives --install /bin/gcc gcc /usr/bin/gcc-13 100 |
The command will create a link /bin/gcc
which is linked to
/etc/alternatives/gcc
. /etc/alternatives/gcc
is linked to /usr/bin/gcc-13
or /usr/bin/gcc-14
. Use sudo update-alternatives --config gcc
can change
/etc/alternatives/gcc
is linked to /usr/bin/gcc-13
or /usr/bin/gcc-14
.
Let g++
change with gcc
,
1 | sudo update-alternatives --install /bin/gcc gcc /usr/bin/gcc-13 100 --slave /bin/g++ g++ /usr/bin/g++-13 |
2. sudo apt update error: “Release file is not yet valid” in WSL.
Run sudo hwclock --hctosys
. This command gets the latest time from your
Windows machine’s RTC and sets the system time to that.
3. Proxy for apt
/etc/apt
is the host directory for apt.
/etc/apt/apt.conf.d/proxy.conf
defines the proxy only for apt.
If one wants to define proxy globally, export http(s)_proxy
should be used.
4. Shortcuts
I want to find out where the “kill” shortcut, ctrl C, defined. I use bind -P
to check the shortcuts. However, do not find ctrl C. Thus, I learned something
about the shortcuts on linux. ctrl C is a shortcut of stty. However, bind -P
lists the shortcuts of readline.
There may be two kinds of shortcuts, in practice,
- stty shortcuts
- readline shortcuts
4.1. stty (set tty, set teletypewriter)
The difference between shell, terminal and tty
tty: Print the file name of the terminal connected to standard input.
stty: change or print terminal characteristics, change and print terminal line settings.
They are related to terminal.
- terminal = tty = text input/output environment
- console = physical terminal
- shell = command line interpreter
The input of terminal or tty will used by readline, but not always readline.
4.2. gun readline - get a line from a user with editing
4.2.1. Synopsis
1 |
|
4.2.2. Description
readline will read a line from the terminal and return it, using prompt as a prompt.
If prompt is NULL or the empty string, no prompt is issued. The line returned is
allocated with malloc
; the caller must free it when finished. The line
returned has the final newline removed, so only the text of the line remains.
4.2.3. Return Value
readline returns the text of the line read. A black line returns the empty string. If EOF is encountered while reading a line, and the line is empty, NULL is returned. If an EOF is read with a non-empty line, it is treated as a newline.
4.2.4. Initialization file
Readline is customized by putting commands in an initialization file (the
inputrc
file). The name of this file is taken from the value of the INPUTRC
environment variable. If that variable is unset, the default is ~/.inputrc
. If
that file does not exist or cannot be read, the ultimate default is
/etc/inputrc
.
When a program which uses the readline library starts up, the init file is read, and the key bindings and variables are set.
There are only a few basic constructs allowed in the readline init file.
- Black lines are ignored.
- Lines beginning with a
#
are comments. - Lines beginning with a
$
indicate conditional constructs. - Other lines denote key bindings and variable settings.
Each program using this library may add its own commands and bindings.
For example, placing
1 | M-Control-u: universal-argment |
into the inputrc
would make M-C-u
execute the readline command
universal-argument
.
5. The difference of help
and man
on linux
help
displays information about builtin shell commands.
man
is s system-wide documentation system that provides short reference
manuals for individual commands, API functions, concepts, configuration file
syntax, file formats. It is the traditional Unix documentation system.
We can get the information of cd
by help cd
, but not by man cd
. We can get
the information of git/nvim/stty
by man git/nvim/stty
, but not by
help git/nvim/stty
. cd
is a shell command and git/nvim/stty
is linux
projects.