Calculate the stat of a column of numbers
Suppose we have a file where each line a number, and we want to the get stat of these numbers on the command line.
If Python is installed in the system, we can use the following command:
cat data.log | python3 -c "import fileinput as FI,statistics as STAT; i = [float(l.strip()) for l in FI.input()]; print('min:', min(i), ' max: ', max(i), ' avg: ', STAT.mean(i), ' median: ', STAT.median(i))"
We can also use jq to calculate the stat:
jq -s min data.txt
jq -s max data.txt
jq -s add/length data.txt
What if I screw up the PATH variable?
I edit the
.bash_profileand update the
PATH variable wrongly, something
After sourcing this file, all my commands fails. This is because the system
PATH variable to find the suitable executable to run.
However, we can always run an executable with its absolute path, so the remedy
is to use vim to edit
Search pattern only in package names
apt search --names-only pattern
pattern supports regular expressions. For example, to search package starting
apt search --name ^man
I was forced log out after a short time of inactivity?
I connect to a remote server via my ssh client. I noticed that after even a few minutes of inactivity, I was forced log out, and saw the following message:
timed out waiting for input: auto-logout
It turns out bash a feature to log out the user using the
TMOUT env variable.
TMOUT=3600 will force user to log out after waiting 3600 seconds
for user input (but no input is coming). Set
TMOUT to 0 will disable this
- How to keep idle session from exiting
Find which package provides a file or what file a package contains on Ubuntu
To find which package provides a certain file, we can use
dpkg -S /path/to/file
dpkg -S /usr/lib/python3/dist-packages/uno.py shows the following
We can also use apt-file to find which package a file belongs to:
apt update && apt instal apt-file apt-file update apt-file search /path/to/file
To find what file a package contains, we can to this Ubuntu packages site
and search a package. In the package detail info page, we can click the
[list of files] to get the files contained in a certain release for an architecture
(see here for an example).
License CC BY-NC-ND 4.0