2019年8月27日 星期二

Error while loading shared libraries: libxxx.so.3: cannot open shared object file: No such file or directory

Typically, it will check /lib, /usr/lib as default library folder while running.

But if your program is using library from another folder,
you should specify it use -L option in gcc:
gcc -Wall hello.c -L/usr/local/lib/x86_64-linux-gnu -lhello -o hello

It will load libhello.so in /usr/local/lib/x86_64-linux-gnu folder

But I still get error after running above command.
To fix it:
$ sudo ldconfig /usr/local/lib/x86_64-linux-gnu

Then build again, it can run successfully.

2019年8月26日 星期一

Install pip3 on ubuntu16.04

1. Get get-pip.py on https://bootstrap.pypa.io/get-pip.py

2. Run sudo python3.5 get-pip.py --prefix=/usr/local/
    It will install pip packages in /usr/local folder

3. Then you can check packages are up-to-date by command:
    pip install --upgrade pip setuptools wheel

Reference:
https://packaging.python.org/tutorials/installing-packages/#requirements-for-installing-packages

2019年8月19日 星期一

Usage of Linux csplit

csplit是將一個文件分成數個小區塊的工具

如果有個檔案text內容為:
  Title 1
  aaa
  bbb

  Title 2
  ccc
  ddd

  Title 3
  eee
  fff

想根據"Title"來分段:
$ csplit text -s -f title -b "%02d.log" /Title/ {*}

-s: 靜默模式
-f: 產生的檔名的前綴, 這邊為titlexxx
-b: 產生的檔名的後綴, 這邊為xxx00.log
/Title/: Parse用來分段的pattern
{*}: 執行pattern的次數, {1}為找一次, *為找到沒有為止

執行結束後會產生幾個檔案:
title00.log title01.log title02.log title03.log

通常會發現第一個檔案(title00.log)是空的
因為第一個檔案存的是第一個Title之前的資料,
如果text內容如下:
  zzz
  Title 1
  aaa
  bbb
  ...

那title00.log內容就會是zzz

其他依序如下
title01.log:
  aaa
  bbb

title02.log:
  ccc
  ddd

title03.log:
  eee
  fff

注意檔案內容不會包含pattern

2019年8月3日 星期六

[工作] Setup docker image時出現no space

最近發現在setup docker時會出現no space然後失敗

稍微查了一下發現
docker setup後會存放在/var/lib/docker目錄下
這個目錄占了我大概70G的空間(setup許多docker的結果)
而我的kernel只分配100G左右
幾乎被占滿了

目前好像沒有好方法
只能盡量把沒用到的image刪一刪了

還有之後有用docker的話
重新建系統可能考慮把root空間加大了