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.

Use python

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))"

Use jq

We can also use jq to calculate the stat:

  • min: jq -s min data.txt
  • max: jq -s max data.txt
  • average: 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 like this:

export PATH="/some/path"

After sourcing this file, all my commands fails. This is because the system relies on 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 .bash_profile:

/usr/bin/vim ~/.bash_profile


Search pattern only in package names

apt search --names-only pattern

pattern supports regular expressions. For example, to search package starting with a man:

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. For example, 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 feature.


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 command:

dpkg -S /path/to/file

For example dpkg -S /usr/lib/python3/dist-packages/ shows the following message:

python3-uno: /usr/lib/python3/dist-packages/

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).