打印全部列
awk '{print $0}'
打印指定列
awk '{print $2,$4}'
打印指定列并拼接字符串
awk '{print $1,"hhah",$2}'
awk '{print $1"hahah"$2}'
按指定分隔符取列
awk -F: '{ print $1 }'
打印某一列及后面所有列的内容
awk '{out=""; for(i=2;i<=NF;i++){out=out" "$i}; print out}'
打印最后一列,最后一列的前一列,NF表示最后一列的列号
awk '{print $NF, $(NF-1)}'
打印指定一行,NR表示行号
awk 'NR==6 {print $0}'
打印第六行,以 :分隔开的第一列
awk -F ":" 'NR==6 {print $1}'
打印第4行以后的行
git log --pretty=format:"%H-%h:%h" -n 15 |cat -n | awk 'NR>4 {print $0}'
5 1f021028e22d92119fa5a0821273596e0c37be87-1f02102:1f02102
6 f36b0ad5a376edf485979b357af4ac1df87cc443-f36b0ad:f36b0ad
7 e3776955f8f3592051603d2299b93d3b55cbc52a-e377695:e377695
8 94c50a1fd810d5c1e62535fac8f6db3c01c4c476-94c50a1:94c50a1
git log --pretty=format:"%H-%h:%h" -n 15 |cat -n | awk 'NR<4 {print $0}'
git log --pretty=format:"%H-%h:%h" -n 15 |cat -n | awk 'NR<=4 {print $0}'
条件用法
打印包含 Merge branch 的行 用/strings/
git log --pretty=format:"%
p2top3命令批量转化语法之后,还有一些 版本2和3之间用法的差异需要手动调整:
列表本目录所占空间
du -sh ./
列表子目录所占空间
du -sh ./*
列表子目录所占空间达到不足1M的
du -sh ./* | grep "^[0-9]\{1,\}.\{0,1\}[0-9]\{1,\}[K]"
列表子目录所占空间达到1M 以上
du -sh ./* | grep "^[0-9]\{1,\}.\{0,1\}[0-9]\{1,\}[M,G]"
列表子目录所占空间达到1G 以上
du -sh ./* | grep "^[0-9]\{1,\}.\{0,1\}[0-9]\{1,\}[G]"
每个级别的列表再按第一列数值排序
du -sh ./* | grep "^[0-9]\{1,\}.\{0,1\}[0-9]\{1,\}[K]"| sort -n
du -sh ./* | grep "^[0-9]\{1,\}.\{0,1\}[0-9]\{1,\}[M]"| sort -n
du -sh ./* | grep "^[0-9]\{1,\}.\{0,1\}[0-9]\{1,\}[G]"| sort -n
在排了序基础上再取最大10 个
du -sh ./* | grep "^[0-9]\{1,\}.\{0,1\}[0-9]\{1,\}[G]" | sort -n | tail -n 10
# <file system> <mount point> <type> <options> <dump> <pass>
以下是官方对fstab 里六个字段用法的解释
For ordinary mounts, it will hold (a link to) a block special device node (as created by mknod(2)) for the device to be mounted, like /dev/cdrom' or
/dev/sdb7'.
LABEL= < label > or UUID= < uuid >
LABEL=< label> or UUID=< uuid> may be given instead of a device name. This is the recommended method, as device names are often a coincidence of hardware detection order, and can change when other disks are added or removed. For example, LABEL=Boot' or
UUID=3e6be9de-8139-11d1-9106-a43f08d823a6'. (Use a filesystem-specific tool like e2label(8), xfs_admin(8), or fatlabel(8) to set LABELs on filesystems).
第一个字段可以是分区名,或标签名,设备id, 用来标记这一行所表示 的文件系统所在的设备块
root@vm1:/vob/GuaKing/DevOps# cat /etc/fstab
# <file system> <mount point> <type> <options> <dum
diskimage-builder code
https://opendev.org/openstack/diskimage-builder官方分区设置
https://docs.openstack.org/diskimage-builder/latest/user_guide/building_an_image.html
If you wish to customise the top-level block-device-default.yaml file
from one of the block-device-* elements, set the environment variable
DIB_BLOCK_DEVICE_CONFIG. This variable must hold YAML structured
configuration data or be a file:// URL reference to a on-disk
configuration file.
在自己自定义的element 的根目录下,创建一个文件block-device-default.yaml,将分区方案按yaml 文件格式配置其中,如果element 下方有一个block-device-default.yaml,则会优先使用用户定义的分区配置,如果用户无定制,则使用默认配置:
https://opendev.org/openstack/diskimage-builder/src/branch/master/diskimage_builder/elements/block-device-mbr/block-device-default.yaml
或使用变量DIB_BLOCK_DEVICE_CONFIG定义分区配置,将block-device-default.yaml的文本赋值给DIB_BLOCK_DEVICE_CONFIG
磁盘全部容量分配r
背景: 使用kvm 安装 qcow2 文件 ,启用一个ubuntu 虚拟机。
qemu-img info a.qcow2
qemu-img create -f qcow2 -o preallocation=metadata b.qcow2 60G
virt-resize --expand /dev/sda1 a.qcow2 b.qcow2
#第一个命令查看a.qcow2 镜像磁盘有多大(a 包含我们要安装系统镜像)
#第二个命令创建一块 60G 的镜像磁盘文件(即最终磁盘容量,b须比a大)
#第三个命令,将a 镜像内容拷到b镜像中,并将空闲空间(b'size-a'size)扩展到/dev/sda1 分区上。
#即,如果a.qcow2 原磁盘大小是50G ,执行完命令后b.qcow2 除了是a.qcow2 的完整拷贝外,b.qcow2中的/deb/sda磁盘大小为60G,其中/dev/sda1 分区 比a.qcow2 中/dev/sda1 多了10G.
qemu-img resize a.qcow2 +5G
virsh destroy vm
virsh start vm
## enter vm
fdisk -l | grep sda (/dev/sda 磁盘大小增加了5g, 但是分区 /dev/sda1 未拿到这些空间)
parted /dev/sda (将磁盘的未分配空间,分配给分区sda1)
(parted) p
(parted) resizepart 1
(parted) quit
## 执行log 如下:
root@CASA-MOBILE:~# parted /dev/sda
(parted) p <== remember space of all disk /dev/sda ,and remember the Number of sda1
在使用diskimage-builder生成qcow2 镜像时,磁盘空间足够,但是执行到中间时会报
No space left
用df -h 查看时,/目录下的空间足够。
于是再执行,在执行过程中发现,diskimage-builder在执行过程解包和拷贝过程是会将一个/tmp/dib_build.xxxxxx的临时目录挂载在tmpfs上,而当前系统的tmpfs 只有3.9G 。
root@vm1:~# df -h| grep tmpfs
tmpfs 797M 3.3M 793M 1% /run
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 797M 0 797M 0% /run/user/0
tmpfs 3.9G 3.8G 154M 97% /tmp/dib_build.whmZyNdv
tmpfs 3.9G 0 3.9G 0% /tmp/dib_image.6Jdr8dSL
了解tmpfs是在哪里分配及分配规则:
https://wiki.archlinux.org/index.php/Tmpfs
tmpfs is a temporary filesystem that resides in memory and/or swap
partition(s). Mounting directories as tmpfs can be
在ubuntu系统上,安装一系列依赖,及打包工具diskimage-builder, 然后在其上执行包含
disk-image-create 命令的脚本,生成qcow2/vmdk镜像。
每个人想拥有自己的构建环境 ,都需要另外在自己的系统上安装所需要的软件列表,会存在系统版本和软件版本不一的情况。
将其上环境构建成固定的dokcer 镜像, 每个人不管自己的设备是redhat, centos, ubuntu,都可以使用可控版本的打包容器进行构建,并且使用的软件版本是一致的。使用的镜像基于基础系统另装了哪些工具,都是可追溯可控版的。
将需要定义的变量,需要预装的软件,都写进dockerfile
FROM ubuntu:bionic AS DIB-env
COPY sources.list /etc/apt/
RUN apt-get update
RUN apt-get install -y python-pip
RUN apt-get install -y qemu-utils
RUN apt-get install -y sudo
RUN apt-get install -y curl
RUN apt-get install -y squashfs-tools
# Install python packages
RUN pip install --upgrade pip
RUN pip install networkx -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
RUN pip install diskimage-builder -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
ENV TEMP_PATH=/vob_temp
RUN mkdir -p ${TEMP_PATH}
COPY temp.tar.gz ${TEMP_PATH}
WORKDIR ${TEMP_PATH}
RUN tar zxvf temp.tar.gz
RUN r
Dockerfile 里的 pip install 总是failed .但是直接执行可以成功。
估计是docker build 时默认使用的pip 源有太慢导致
RUN pip install networkx
Step 9/15 : RUN pip install networkx
---> Running in 3a3f19067b2f
Collecting networkx
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed ox/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed ox/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed ox/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutErr
apt-get install -y dnsmasq
root@node248:/etc/resolvconf/resolv.conf.d# cat /etc/dnsmasq.conf | grep -v "^#|^$"
port=53
resolv-file=/etc/resolv.conf
strict-order
listen-address=172.0.11.248
addn-hosts=/etc/hosts
root@node248:/etc/resolvconf/resolv.conf.d# cat /etc/hosts
#.....
172.0.11.2 vm2
172.0.11.3 vm3
172.0.11.4 vm4.com
使用服务器本身的dns 列表,则resolv-file=/etc/resolv.conf
使用服务器上另外的dns 列表文件,即上游dns,则resolv-file=/etc/dnsmasq.d/ 此目录下放置 *conf
#14
service dnsmasq restart
#18
systemctl restart dnsmasq
客户端将此服务器ip 设置为dns 之后,查找域名时,会通过服务器的/etc/hosts 去解析域名,然后再通过resolv-file 中列的dns 去解析。
UBUNTU 14
root@vm1:/etc/dnsmasq.d# cat /etc/resolvconf/resolv.conf.d/base
nameserver 172.0.11.248
root@vm1:/etc/dnsmasq.d# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#