289篇 Default中的文章

KVM虚拟化之libguestfs-tools工具常用命令介绍

libguestfs-tools可以通过yum install -y libguestfs-tools 安装。
安装libguestfs-tools工具后,会产生一系列命令如下:

[root@kvm01 ~]# virt-
virt-alignment-scan  virt-df              virt-inspector       virt-rescue          virt-win-reg
virt-builder         virt-diff            virt-install         virt-resize          virt-xml
virt-cat             virt-edit            virt-log             virt-sparsify        virt-xml-validate
virt-clone           virt-filesystems     virt-ls              virt-sysprep         
virt-copy-in         virt-format          virt-make-fs         virt-tar-in          
virt-copy-out        virt-host-validate   virt-manager         virt-tar-out         
virt-customize       virt-index-validate  virt-pki-validate    virt-what 
More ~

nginx配置重定向 HTTP到HTTPS

Redirect All HTTP

server {
    listen 80 default_server;

    server_name _;

    return 301 https://$host$request_uri;
}

Redirect Specific Sites

server {
    listen 80;

    server_name foo.com;
    return 301 https://foo.com$request_uri;
}
More ~

禁用ubuntu ssh连接后的欢迎信息

本文的目的是在Ubuntu 20.04 Focal Fossa Linux上禁用动态motd和新闻。
20200723004336.png

  • 在本教程中,您将学习:
  • 如何修改登录新闻
  • 如何修改动态消息
  • 如何在系统范围内使motd动态消息屏蔽
  • 如何使每个用户的motd动态消息屏蔽
More ~

Linux 命令:flock - 对打开的文件加锁或解锁

先来看看flock -h 的用法:

Usage:
 flock [options] <file|directory> <command> [command args]
 flock [options] <file|directory> -c <command>
 flock [options] <file descriptor number>

Options:
 -s  --shared             get a shared lock
 -x  --exclusive          get an exclusive lock (default)
 -u  --unlock             remove a lock
 -n  --nonblock           fail rather than wait
 -w  --timeout <secs>     wait for a limited amount of time
 -E  --conflict-exit-code <number>  exit code after conflict or timeout
 -o  --close              close file descriptor before running command
 -c  --command <command>  run a single command string through the shell

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see flock(1).
More ~

go语言格式化打印fmt的参数

go 软件包fmt使用与C的printf和scanf类似的功能实现格式化的I / O。

概要:

%v	默认格式的值,打印结构时,加号(%+ v)添加字段名称
%#v	该值的Go语法表示形式
%T	值类型的Go语法表示形式
%%	文字百分号;没有任何价值

Boolean:

%t	单词true或false

Integer:

%b	2进制
%c	相应的Unicode代码点表示的字符
%d	10进制
%o	8进制
%O	以0o为前缀8进制
%q	使用Go语法安全地转义的单引号字符文字。
%x	16进制的a-f小写字母
%X	16进制的A-F大写字母
%U	Unicode格式:U + 1234;与“ U +%04X”相同
More ~

python 的subprocess 模块使用详解

一、简介

  subprocess最早在2.4版本引入。用来生成子进程,并可以通过管道连接他们的输入/输出/错误,以及获得他们的返回值。

  subprocess用来替换多个旧模块和函数:

  • os.system
  • os.spawn*
  • os.popen*
  • popen2.*
  • commands.*

运行python的时候,我们都是在创建并运行一个进程,linux中一个进程可以fork一个子进程,并让这个子进程exec另外一个程序。在python中,我们通过标准库中的subprocess包来fork一个子进程,并且运行一个外部的程序。subprocess包中定义有数个创建子进程的函数,这些函数分别以不同的方式创建子进程,所欲我们可以根据需要来从中选取一个使用。另外subprocess还提供了一些管理标准流(standard stream)和管道(pipe)的工具,从而在进程间使用文本通信。

More ~