66 篇文章带有标签 “Linux”

SSH 登录欢迎信息

终端登录时显示给用户的欢迎消息,无论是通过远程 SSH 登录还是直接通过 TTY 或终端,是 motd 的一部分,即 Message Of The Day 守护程序。 通过修改 /etc/update-motd.d 目录中的 /etc/motd 文件或脚本,可以自定义 motd 消息以适合每个用户或管理员的个性化需求。

Linux Shell 实践

  • 执行时的所有信息都输出到文件(&>)
echo hello &> log.info
$ cat log.info 
hello
  • 创建一个文件并写入内容(> filename <<EOF)
cat > hello.sh << EOF
#!/bin/bash
echo hello
EOF
  • 整数四则运算(let)
let n=10-3+4/2
echo $n
9
  • 四种执行模式运行
$ vim test.sh
#!/bin/bash
echo $str
$ chmod u+x test.sh
$ bash test.sh 
$ ./test.sh 
$ source test.sh 
hello world
$ . test.sh 
hello world
  • 导出变量(export),父进程定义的变量子进程可见。
$ export str
$ bash test.sh 
hello world
$ source test.sh 
hello world
  • 移除变量(unset)
$ unset str
$ echo $str
  • $$ 当前进程ID
$ echo $$
26102
  • $0 当前进程名
$ echo $0
-bash
  • 显示所有数组元素
$ echo ${ips[@]}
10.0.0.1 10.0.0.2 10.0.0.3

命令tar

    -c, --create Create a new archive.  Arguments supply the names of the files to be archived.
    -x, --extract, --get Extract files from an archive.
    -z, --gzip, --gunzip, --ungzip Filter the archive through gzip(1).
    -j, --bzip2 Filter the archive through bzip2(1).
    -f, --file=ARCHIVE Use archive file or device ARCHIVE.  If this option is not given, tar will first examine the environment variable `TAPE'.  If it is set, its value will be used as the archive  name.   Otherwise, tar will assume the compiled-in default.
    -t, --list List the contents of an archive.
    -v, --verbose Verbosely list files processed.

命令zip

排除所有的 yaml 文件

zip -r yolov5.zip yolov5/ -x "*yolo*.yaml"

只查看文件名 $ zipinfo -1 yolov5.zip yolov5/ yolov5/hubconf.py yolov5/tutorial.ipynb yolov5/Dockerfile yolov5/README.md yolov5/.dockerignore yolov5/models/ yolov5/models/common.py yolov5/models/export.py yolov5/models/yolov5s.yaml yolov5/models/yolo.py yolov5/models/init.py yolov5/models/experimental.py yolov5/models/yolov5m.yaml yolov5/models/yolov5l.yaml yolov5/models/yolov5x.yaml yolov5/LICENSE yolov5/.gitignore yolov5/test.py yolov5/train.py yolov5/weights/ yolov5/weights/download_weights.sh yolov5/requirements.

命令du

du - 估计文件空间使用量

    -s, --summarize display only a total for each argument
    -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)

命令top

  • 查看1号进行
top -p 1
top -p1
top - 22:58:02 up 323 days, 12:09,  2 users,  load average: 0.64, 0.61, 0.38
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
%Cpu(s):  7.2 us,  1.8 sy,  0.0 ni, 90.3 id,  0.0 wa,  0.5 hi,  0.2 si,  0.0 st
MiB Mem :   3780.8 total,    400.2 free,   1749.6 used,   1631.0 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   1939.3 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
    1 root      20   0  178540   7680   3792 S   0.0   0.2   7:50.54 systemd

vim实践

Ubuntu

sudo apt install vim-gtk3

运行

vim -g
gvim
  • :!command 运行shell命令
    • :!ls -l 查看当前目录列表
    • :!ifconfig 查看本地IP地址
  • 选择
    • v 进入字符可视
      • w 选择下一个单词
      • 0 选择到行首
      • $ 选择到行尾
    • c 剪切选择的字符
    • d 删除选择的字符
    • x 删除选择的字符
    • ggVG 选择所有的字符
  • 复制
    • y 复制选择的字符
    • :%y 复制所有的字符
    • 当前行
      • dd 剪切当前行
        • 3dd 剪切3行
      • y$ 复制当前字符到行尾
      • :y 复制当前行
      • yy 复制当前行
        • 3yy 复制3行
    • 剪切板(用于应用之间的交换)
      • :y+ 复制光标所在行(也可以先使用块的方式进行选择再复制)
      • :%y+ 复制所有数据
  • p 粘贴
  • 删除
    • x 删除当前字符
    • :1,$d 删除所有行(1第一行开始,$直到文件末尾,d删除)
    • dw 删除光标所在字符到单词的末尾
    • diw 删除光标所在的整个单词
    • d0 删除光标所在字符到行首
    • d$ 删除光标所在字符到行尾
    • dG 删除光标所在行到文件末尾

:%s/search_word/replace_word/g 替换(全文) :1,$s/search_word/replace_word/g 替换(全文) :3,4s/search_word/replace_word/g 替换(3-4行) :%s/search_word//g 删除(全文) :

命令ln

在文件之间建立链接

    ln [OPTION]... [-T] TARGET LINK_NAME
    ln [OPTION]... TARGET
    ln [OPTION]... TARGET... DIRECTORY
    ln [OPTION]... -t DIRECTORY TARGET...
  1. rm
rm /var/www/ubuntu

命令chown

更改文件所有者和组

    chown [OPTION]... [OWNER][:[GROUP]] FILE...

基于Apt-Mirror创建私有Ubuntu存储库

  1. 配置mirror.list
sudo nano /etc/apt/mirror.list
############# config ##################
set base_path    /data/apt-mirror
#set mirror_path  $base_path/mirror
#set skel_path    $base_path/skel
#set var_path     $base_path/var
#set cleanscript $var_path/clean.sh
#set defaultarch  <running host architecture>
#set postmirror_script $var_path/postmirror.sh
#set run_postmirror 0
set nthreads     20
set _tilde 0
############# end config ##############
deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu focal-security main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu focal-proposed main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
clean http://archive.ubuntu.com/ubuntu

Apache HTTP Server实践

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 8081
......
......
  • /etc/apache2/sites-enabled/000-default.conf
sudo nano /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:8081>
......
......
</VirtualHost>
  • 重启服务
sudo systemctl restart apache2

Building ONNX Runtime

  • 拉取容器(编译环境)
docker pull nvidia/cuda:11.1-cudnn8-devel-ubuntu20.04
  • 运行容器
docker run -it --name build-onnxruntime-gpu --runtime nvidia \
    -v $(pwd)/onnxruntime:/onnxruntime -w /onnxruntime \
    nvidia/cuda:11.1-cudnn8-devel-ubuntu20.04
  • 更新apt镜像源
sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
apt-get update
  • 安装依赖包
apt-get install language-pack-en git cmake python3 python3-pip -y
  • 修改语言环境
locale-gen en_US.UTF-8
update-locale LANG=en_US.UTF-8
  • 更新pip镜像源
pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/
  • 安装numpy
pip3 install numpy

编译 ./build.

命令ffmpeg

  • 生成gif(低质量) -pix_fmt(像素格式) -s(设置帧大小WxH)
ffmpeg -y -i input.mp4 -pix_fmt rgb8 -r 10 -s 320x240 output.gif
ffmpeg -y -i input.mp4 -pix_fmt rgb8 -r 10 -vf 'scale=320:-1' output.gif
  • 生成gif(高质量) -ss(开始时间偏移) -t(持续时间)
ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
ffmpeg -y -ss 5 -t 5 -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
  • 每秒抽取一张图片 -r(设置帧速率)
ffmpeg -i input.mp4 -r 1 -s 1024x768 -f image2 input-%03d.jpeg