0%

linux command ref

Guide

ln

1
2
3
ln -s src dest

ln -s $(pwd)/yolo /home/kezunlin/program/darknet/kzl-yolo

tips: use absolute path to link folder

sed

case1

1
sed -i "s/old/new/g" 1.txt

replace “old” with “new”

case2

1
sed -i "7,7s/neat_enable\: false/neat_enable\: true/g" _config.yml

replace neat_enale: false to neat_enale: true

case3

1
sed -i "s/http:\/\/kezunlin.me/https:\/\/kezunlin.me/g" posts/post1.md

replace “http://kezunlin.me“ with “https://kezunlin.me

grep

case1

1
2
3
4
5
grep UpsampleParameter . -r --include *.h 

grep UpsampleParameter . -r --include *.proto
./src/caffe/proto/caffe.proto: optional UpsampleParameter upsample_param = 150;
./src/caffe/proto/caffe.proto:message UpsampleParameter {

case2

1
2
3
4
grep -r "http://kezunlin.me" posts/ 
posts/post1.md:[here](http://kezunlin.me/post/book)
posts/post2.md:-[here](http://kezunlin.me/post/book)
posts/post2.md:- [img](http://kezunlin.me/post/book)

case3

1
2
3
grep -rl "http://kezunlin.me" posts 
posts/post1.md
posts/post2.md

case4

1
sed -i "s/http:\/\/kezunlin.me/https:\/\/kezunlin.me/g" `grep -rl "http://kezunlin.me" posts`  

replace http://kezunlin.me with https://kezunlin.me in all posts files.

case5

1
sed -i "s/comments\: false/comments\: true/g" _posts/*

replace comments: false with comments: true in all posts files.

case6

1
2
3
4
grep --include=*.py -lr OKUtil .  | xargs 

grep -r -l <old> * | xargs sed -i 's/<old>/<new>/g'
grep -r -l <OKUtil> * | xargs sed -i 's/<OKUtil>/<OkoooUtil>/g'

ldd

for so

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ldd test_opencv | awk '/ => / { print $3 }'
(0x00007fff309d4000)
/usr/local/lib/libopencv_imgcodecs.so.3.1
/usr/local/lib/libopencv_core.so.3.1
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/lib/x86_64-linux-gnu/libgcc_s.so.1
/lib/x86_64-linux-gnu/libc.so.6
/usr/local/lib/libopencv_imgproc.so.3.1
/usr/local/lib/libjpeg.so.8
/lib/x86_64-linux-gnu/libpng12.so.0
/usr/lib/x86_64-linux-gnu/libtiff.so.5
/usr/lib/x86_64-linux-gnu/libjasper.so.1
/lib/x86_64-linux-gnu/libz.so.1
/lib/x86_64-linux-gnu/libm.so.6
/lib/x86_64-linux-gnu/libpthread.so.0
/lib/x86_64-linux-gnu/libdl.so.2
/lib/x86_64-linux-gnu/librt.so.1
/lib/x86_64-linux-gnu/liblzma.so.5
/usr/lib/x86_64-linux-gnu/libjbig.so.0

for not found

1
ldd test_opencv | awk 'NF==1 {file=$1} /not found/ { print file, $1 }'

useful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ldd example_opencv | awk  '{if (match($3,"/")){ printf("%s \n"),$3 } }'
/usr/local/lib/libopencv_imgcodecs.so.3.1
/usr/local/lib/libopencv_core.so.3.1
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/lib/x86_64-linux-gnu/libgcc_s.so.1
/lib/x86_64-linux-gnu/libc.so.6
/usr/local/lib/libopencv_imgproc.so.3.1
/usr/local/lib/libjpeg.so.8
/lib/x86_64-linux-gnu/libpng12.so.0
/usr/lib/x86_64-linux-gnu/libtiff.so.5
/usr/lib/x86_64-linux-gnu/libjasper.so.1
/lib/x86_64-linux-gnu/libz.so.1
/lib/x86_64-linux-gnu/libm.so.6
/lib/x86_64-linux-gnu/libpthread.so.0
/lib/x86_64-linux-gnu/libdl.so.2
/lib/x86_64-linux-gnu/librt.so.1
/lib/x86_64-linux-gnu/liblzma.so.5
/usr/lib/x86_64-linux-gnu/libjbig.so.0

curl

login website with json data

1
2
3
4
curl -X POST \
-H "Accept: application/json" -H "Content-type: application/json" \
--data '{"name":"admin","password":"21232f297a57a5a743894a0e4a801fc3"}' \
http://192.168.0.12:8888/api/login

md5(admin) = 21232f297a57a5a743894a0e4a801fc3

output

{"rtn":0,"message":"OK","session_id":"[email protected]"}

query results with session_id

1
2
3
curl -X GET \
-H "session_id: [email protected]" \
http://192.168.0.12:8888/api/book

download file

1
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

Tips

check cpu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c 
8 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz


cat /proc/cpuinfo | grep physical | uniq -c
1 physical id : 0
1 address sizes : 39 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 39 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 39 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 39 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 39 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 39 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 39 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 39 bits physical, 48 bits virtual

check gpu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
lspci | grep -i vga
00:02.0 VGA compatible controller: Intel Corporation Device 591b (rev 04)
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1c20 (rev a1)


lspci -v -s 01:00.0
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1c20 (rev a1) (prog-if 00 [VGA controller])
Subsystem: CLEVO/KAPOK Computer Device 65a1
Flags: bus master, fast devsel, latency 0, IRQ 130
Memory at db000000 (32-bit, non-prefetchable) [size=16M]
Memory at 90000000 (64-bit, prefetchable) [size=256M]
Memory at a0000000 (64-bit, prefetchable) [size=32M]
I/O ports at e000 [size=128]
[virtual] Expansion ROM at dc000000 [disabled] [size=512K]
Capabilities: <access denied>
Kernel driver in use: nvidia
Kernel modules: nvidiafb, nouveau, nvidia_396, nvidia_396_drm


nvidia-smi
Tue Feb 12 10:09:14 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 396.54 Driver Version: 396.54 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1060 Off | 00000000:01:00.0 Off | N/A |
| N/A 56C P8 8W / N/A | 601MiB / 6078MiB | 3% Default |
+-------------------------------+----------------------+----------------------+


watch -n 1 nvidia-smi

pip install gpustat
watch --color -n1 gpustat -cpu

multiple terminal

1
gnome-terminal --working-directory=/home --tab --tab --tab

stop lightdm

1
2
3
4
5
6
sudo apt-get install xserver-org

# stop desktop
sudo /etc/init.d/lightdm stop

sudo fbterm

changedir no effect

changedir.sh

1
2
3
#!/bin/bash
cd /home/firefox
pwd

执行的时候是./changedir.sh来执行的,这样执行的话终端会产生一个subshell,subshell去执行脚本,在subshell中已经切换了目录了,但是subshell一旦执行完,马上退出,subshell中的变量和操作全部都收回。回到终端根本就看不到这个过程的变化。

solution

1
2
3
source ./changedir.sh
# or
. changedir.sh

source changedir.sh执行,这时候就是直接在终端的shell执行脚本了,没有生成子shell,所以当前终端切换了目录。

kill process

1
2
3
lsof -i:4000
netstat -tunlp | grep 4000
kill -9 1234

Reference

History

  • 20181130: created.