惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
The Cloudflare Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
L
LangChain Blog
Recent Announcements
Recent Announcements
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
I
InfoQ
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
H
Help Net Security
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
B
Blog RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Linux Tips and Tricks -- s3
2020-12-22 · via jdhao's digital space

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

Ref:

What if I screw up the PATH variable?#

I edit the .bash_profileand update the PATH variable wrongly, something like this:

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

Ref:

Search pattern only in package names#

apt search --names-only pattern

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

Ref:

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.

Ref:

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:

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

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

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

Ref: