dd_linux_command

dd命令

文件输入输出

1
2
3
#if= 接输入文件
#of= 接输出文件
dd if=/dev/zero of=./zero.file

字节数调整

1
2
3
4
#bs= 设置输入文件 输出文件 块大小
#ibs= 仅设置输入文件 块大小
#obs= 仅设置输出文件 块大小
dd if=/dev/zero of=./zero.file bs=4096

指定参数转换文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#conv=指定参数 
# ascii ebcdic转换为ascii
# ebcdic ascii转换为ebcdic
# ibm ascii转换为alternate ebcdic
dd if=test of=out conv=ebcdic

#cbs= 设置每次转换缓冲区大小
dd if=test of=out conv=ebcdic cbs=1024

#block 把每一行转换位长度位cbs 不足部分用空格填充
dd if=test of=out cbs=16 conv=block,ebcdic
#unblock 使每一行的长度都为cbs 不足部分用空格填充
dd if=test of=out cbs=32 conv=unblock,ascii

#lcase 把大写字母转为小写
dd if=test of=out cbs=16 conv=lcase,ascii
#ucase 把小写字母转为大写
dd if=test of=out cbs=64 conv=ucase,ebcdic

#swab 交换输入的每对字节
dd if=test of=out cbs=2 conv=swab

#noerror 出错时不停止
#notrunc 不截短输出文件
#sync 将每个输入块填充盗ibs个字节

跳过一定字节再开始复制

1
2
3
4
5
#skip=nblocks 从输入文件开头跳过n个块后再开始复制
dd if=test of=out skip=10

#seek=nblocks 从输出文件开头跳过n个块后再开始复制
dd if=test of=out seek=12

split_linux_command

split 命令

根据行数分割

1
2
#将test.txt文件 每10行分割成一系列 新的文件 x开头 后缀为字母
split -l 10 test.txt

根据大小分割

1
2
3
# 将test.txt文件 每10K分割成一系列 新的文件 x开头 后缀为字母
# -b 单位byte k M G
split -b 10k test.txt

根据单行大小分割

1
2
# 根据单行最大不超过32byte 进行分割 尽量保证每行的完整性 如换行符直
split -C 32 test.txt

使用数字作为后缀

1
2
#使用数字作为后缀 每10行分割 test.txt文件
split -l 10 test.txt -d

指定后缀字符数量

1
2
#每行16byte 以3为数字作为后缀 分割test.txt文件
split -C 16 test.txt -d -a 3

更改输出前缀

1
2
#每16byte split最为输出名前缀 分割test.txt文件
split -b 16 test.txt split

find_linux_command

find 命令

根据文件名查找

1
2
3
4
5
6
7
8
9
10
#-name 跟文件名 可用通配符
#-iname 忽略大小写

#-regex 跟文件路径字符串
#-iregex 忽略大小写

#-prune 不寻找字符串作为范本样式

#在当前目录查找test开头 sh结尾的文件
find ./ -iname "test*.sh"

根据属主 属组查找

1
2
3
4
5
6
7
8
9
#-user username
#-group groupname
#-uid UserID
#-gid GroupID
#-nouser 没有属主
#-nogroup 没有属组

#在当前文件查找属主是root 以pass开头的文件
find ./ -user root -name "pass*"

根据文件类型查找

1
2
3
4
#-type f普通文件 d目录文件 l符号链接 s套接字文件 b块设备文件 c字符设备文件 p管道文件

#在当前目录查找myDemo开头的目录文件
find ./ -type d -name "myDemo*"

组合条件

1
2
3
#-a and与
#-o or或
#-not -! 非

根据文件大小查找

1
2
3
4
#-size b c w k M G

#在当前目录查找文件大小大于10M小于10G的普通文件
find ./ -type f -size -10G -size +10M

根据时间戳查找

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#以天为单位
#-atime 最近访问时间
#-mtime 最近修改文件内容时间
#-ctime 最近修改元数据时间

#以分钟为单位
#-amin
#-mmin
#-cmin

#高级
#-daystart 从本日开始计算时间
#-newer <参考文件或目录> 查找其更改时间更接近现在的文件或目录
#-anewer <参考文件或目录>
#-cnewer <参考文件或目录>

#在当前目录查找比new文件修改时间更新的文件或目录
find ./ -type f -newer new

根据权限查找

1
2
3
4
#-perm 4-r 2-w 1-x

#在当前目录查找可读可写的目录
find ./ -type d -perm 555

符号链接处理

1
2
3
4
5
6
7
#-follow 排除符号链接
#-links <链接数目> 查找符合指定的硬链接数目的文件或目录
#-inum <inode 编号> 查找符合指定的inode编号的文件或目录
#-noleaf 不去考虑目录至少需要拥有两个硬链接存在

#在当前目录排除符号链接查找含有pass的普通文件
find ./ -type f -follow -name "*pass*"

查找深度

1
2
3
4
5
6
7
8
#-path <范本样式> 指定字符串做为寻找目录的范本样式
#-ipath 忽略大小写
#-mindepth <目录层级> 设置最小目录层级
#-maxdepth <目录层级> 设置最大目录层级
#-depth 从指定目录下最深层的子目录开始查找

#在当前目录3层深度内查找10天内访问过的普通文件
find ./ -type f -atime -10 -maxdepth 3

处理动作

1
2
3
4
5
6
7
8
9
10
11
#-print 默认处理动作  显示岛屏幕
#-print0 将文件或目录名称列出岛标准输出,格式为全部的名称全在同一行
#-printf <输出格式> 自行设定输出格式
#-ls 类似对查找盗的文件执行“ls -l”命令
#-delete 刹车农户查找盗的文件
#-fls /path/to/somefile 查找到所有文件的长格式信息保存至指定文件种
#-ok COMMAND {} \; 对查找到的每个文件执行由COMMAND指定的命令 每次都会要求用户确认
#-exec COMMAND {} \; 不需要确认

#在当前目录下对所有包含pass的普通文件执行ls -lh命令
find ./ -type f -exec ls -lh {} \; -name "*pass*"

squid-study

安装

1
2
3
4
5
6
7
8
9
10
11
12
#archlinux 安装
sudo pacman -S squid

#更改配置文件
vim /etc/squid.conf
---
http_access allow all

http_port 0.0.0.0:3128
https_port 0.0.0.0:3129 cert=/etc/squid/my.crt key=/etc/squid/myPrivate.key

cache_dir ufs /var/spool/squid 2048 16 256

证书

1
2
3
4
5
openssl req -new -out tank.csr

openssl rsa -in privkey.pem -out myPrivate.key

openssl x509 -in tank.csr -out my.crt -req -signkey myPrivate.key -days 3650

初始化

1
squid -z

端口开放

1
2
sudo iptables -I INPUT -p tcp --dport 3129 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 3128 -j ACCEPT

启动squid

1
2
sudo systemctl start squid
systemctl status squid

stunnel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
sudo pacman -S stunnel

#SERVER
vim /etc/stunnel/stunnel.conf
---
setuid = root
setgit = root
output = /var/log/stunnel.log
debug = 7

[https]
client = no
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
accept=0.0.0.0:4128 #等待远端访问端口
connect=localhost:3128 #连接到本地squid端口
---


#CLIENT
[https]
client = yes
accept = 127.0.0.1:8888 #本地8888端口等待访问
connnect=server_IP:4128 #连接服务端4128端口

自签证书

1
2
3
openssl genrsa -out privatekey.pem 2048
openssl req -new -x509 -key privatekey.pem -out publickey.pem -days 3650
cat privatekey.pem publickey.pem >> /etc/stunnel/stunnel.pem

git_study

安装git

1
sudo pacman -S git

配置git

1
2
3
4
5
6
7
8
9
10
11
12
13
#配置git的用户名 邮箱号
git config --global user.name "your_github_name"
git config --global user.email "your_github_email"

#配置默认使用的文本编辑器
git config --global core.editor vim

#查看配置
git config --list
vim ~/.gitconfig

#查看某个用户的配置
git config user.name

创建仓库

  • git init

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    #初始化一个仓库
    git init

    #初始化newrepo目录为仓库
    git init path/newrepo

    #添加跟踪的文件
    git add *.c
    git add README
    git commit -m "初始化项目版本"
  • git clone

    1
    2
    3
    4
    5
    6
    #克隆远程仓库
    git clone <repo>
    git clone <repo> <directory>

    git clone git://github.com/shcacon/grit.git
    git clone git://github.com/shcacon/grit.git
  • 配置

    1
    2
    3
    4
    5
    6
    7
    8
    #显示当前git配置信息
    git config --list

    #针对当前仓库
    git config -e

    #针对系统上的所有仓库
    git config -e --global

git基本操作

提交与修改

  • git add

    1
    2
    3
    4
    5
    6
    #添加文件到暂存区
    git add [file1] [file2] ...

    #添加目录到暂存区
    git add [dir]
    git add .
  • git status

    1
    2
    3
    4
    #查看git仓库当前状况
    git status
    # -s 显示简短的输出结果
    git status -s
  • git diff

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    #查看工作区和暂存区的差异
    git diff [file]

    #显示暂存区和上一次提交的差异
    git diff --cached [file]
    git diff --staged [file]

    #显示两次提交的差异
    git diff [first-branch]...[second-branch]

    - git commit
    ```shell
    #提交暂存区到本地仓库中
    git commit -m "message"

    #提交暂存区的指定文件到仓库区
    git commit [file1] [file2] ... -m [message]

    #参数设置修改文件后不需要执行git add 命令,直接来提交
    git commit -a

    #先设置提交代码时的用户信息
    git config --global user.name 'yourname'
    git config --global user.email 'test@youremail.com'

版本回退

  • git reset

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    #指定退回到某一次提交的版本
    git reset [--soft | --hard | --mixed] [HEAD]
    #--mixed 重置暂存区文件与上一次的提交保持一致
    #--soft 知识撤回上一次提交
    #--hard 重置工作区,与上一次的提交保持一致
    #HEAD
    HEAD 当前版本
    HEAD^ 上一次版本
    HEAD^^ 上上次版本
    HEAD^^ 上上上次版本

    HEAD-0 当前版本
    HEAD-1 上一次版本
    HEAD-2 上上一次版本
    HEAD-3 上上上一次版本
  • git rm

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #将文件从工作区和暂存区中删除
    git rm <file>

    #强制删除
    git rm -f <file>

    #仅仅将文件从暂存区中移除
    git rm --cached <file>

    #可以递归删除
    git rm -r *
  • git mv

    1
    2
    3
    4
    5
    #移动或重命名
    git mv [file] [newfile]

    #新文件名存在,强制重命名
    git mv -f [file] [newfile]

分支切换

  • git checkout

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    #切换到指定分支
    git checkout <branch-name>

    #创建新分支 并切换到它
    git checkout -b <new-branch-name>

    #切换到前一个分支
    git checkout -

    #将指定文件恢复到最新的提交状态,丢弃所有未提交的更改,这对于撤销不需要的更改非常有用
    git checkout -- <file>

    #切换到特定提交,使用提交哈希值
    git checkout <commit-hash>

    #切换到标签
    git checkout tags/<tag-name>
  • git switch

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #切换到制定分支
    git switch <branch-name>

    #创建一个新分支并切换到它
    git switch -c <new-branch-name>

    #切换到前一个分支
    git switch -

    #切换到标签指向的提交状态
    git switch tags/<tag-name>
  • git restore

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #恢复文件到最新提交状态
    git restore <file>

    #还原文件到暂存区状态
    git restore --staged <file>

    #还原所有未提交的更改
    git restore .

    #还原文件到特定提交的状态
    git restore --source=<commit> <file>

提交日志

  • git log

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    git log  [options] [branch-name | commit-hash] 
    -p 显示提交的补丁 具体修改内容
    --oneline 简洁的一行格式显示提交信息
    --graph 以图形方式显示分支和合并历史
    --decorate 显示分支和标签指向的提交
    --author=<author> 显示特定作者的提交
    --since=<time> 显示指定时间之后的提交
    --until=<time> 显示指定时间之前的提交
    --grep=<模式> 显示包含指定模式的提交消息
    --no-merges 不显示合并提交
    --stat 显示简略统计信息,包括修改的文件和行数
    --abbrev-commit 使用短提交哈希值
    --pretty=<格式> 使用自定义的提交信息显示格式
    --reverse 逆向显示所有日志
  • git blame

    1
    2
    3
    4
    5
    6
    #逐行显示指定文件的每一行代码注释和相关信息
    git blame [option] [path]
    -L <起始行号>,<结束行号> 指定行号范围
    -C 对重命名或拷贝的代码进行溯源
    -M 对移动的代码进行溯源
    --show-stats 显示行数统计信息

git 远程操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#累出当前仓库总已配置的远程仓库
git remote

#列出当前仓库中以配置的远程仓库,显示出URL
git remote -v

#添加一个新的远程仓库
git remote add <remote-name> <remote-url>

#将已配置的远程仓库重命名
git remote rename <old_name> <new_name>

#从当前仓库中删除指定的远程仓库
git remote remove <remote_name>

#修改指定远程仓库的URL
git remote set-url <remote-name> <new-url>

#显示指定远程仓库的详细信息,包括URL和跟踪分支
git remote show <remote-name>
  • git fetch

    1
    2
    3
    4
    5
    #提取远程仓库更新的数据
    git fetch [alias]

    #从远程仓库提取数据,病尝试合并到当前分支
    git merge [alias] [branch]
  • git pull

    1
    2
    3
    4
    5
    6
    7
    8
    #从远程获取代码并合并到本地版本
    git pull <remote-host> <remote-branch-name>:<local-branch-name>

    #将远程主机origin的master分支拉取过来,与本地的brantest合并起来
    git pull origin master:brantest

    #与当前分支合并
    git pull origin master
  • git push

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #将本地仓库的分支版本上传到远程并合并
    git push <remote-host> <local-branch>:<remote-branch>

    #将本地仓库当前分支master推送到远程origin主机的master分支上
    git push origin master

    #
    git push origin master:master

    #强制执行
    git push --force origin master

    #删除远程主机origin的master分支
    git push origin --delete master

分支管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#列出分支
git branch

#创建分支
git branch <new-branch>

#切换分支
git checkout <branch-name>

#合并分支
git merge

#删除分支
git branch -d <branch-name>
  • git 标签

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #创建带注解的标签
    git tag -a v1.0

    #查看所有标签
    git tag

    #指定标签信息
    git tag -a <tagname> -m "标签"

    #PGP签名标签命令
    git tag -s <tagname> -m "标签"

github

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
#有远程仓库
git remote add [shortname] [url]

#没有仓库
#github注册 新建仓库
#生成SSH-KEY
ssh-keygen -t rsa -C "youremail@example.com"


#查看当前远程库
git remote

git remote -v

#提取远程库
git fetch

#合并远程库
git merge

#推送分支
git push [alias] [branch]

#删除远程仓库
git remote rm [别名]

git 服务器搭建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
groupadd gi
useradd git -g git

cd /home/git
mkdir .ssh
chmod 755 .ssh
touch .ssh/authorized_keys
chmod 644 .ssh/authorized_keys
#收集所有需要登录的用户的公钥,公钥位于id_rsa.pub中

cd /home
mkdir gitrepo
chown git:git gitrepo/
cd gitrepo
git init --bare your.git
chown -R git:git your.git
#初始化仓库

#克隆仓库
git clone git@IP:/home/gitrepo/your.git

docker-study

Docker

安装

1
2
3
4
5
6
7
8
9
10
sudo pacman -S docker                                     #安装docker
sudo systemctl start docker.service #开启docker守护进程
sudo systemctl enable docker.service #设置开启自启动
sudo usermod -aG docker $USER #将自己添加到docker组

#验证安装
docker version
docker info
docker pull hello-world
docker run hello-world

docker镜像加速

1
vim /etc/docker/daemon.json
1
2
3
{
"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
}
1
2
3
4
5
#其他镜像
#网易
https://hub-mirror.c。163.com
#七牛云加速
https://reg-mirror.qiniu.com

使用

  • 例子

    1
    2
    docker pull archlinux          #拉取archlinux:latest 镜像
    docker run --name arch -it archlinux #交互式运行一个arch容器
  • 镜像使用

    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    #列出镜像列表
    docker images
    #REPOSITORY 镜像的仓库原
    #TAG 镜像的标签
    #IMAGE ID 镜像的ID
    #CREATED 镜像创建的时间
    #SIZE 镜像的大小

    #获取一个新镜像
    docker pull ubunt

    #查找容器
    docker search httpd
    #NAEM名字
    #DESCRIPTION 镜像的秒数
    #OFFICIAL 是否是docker官方发布的
    #stars github stars
    #AUTOMATED 自动构建

    #删除镜像
    docker rmi hello-world
    docker rmi image-ID

    #创建镜像
    # 方式1 从已经构建的容器中更新镜像,并且提交这个镜像
    docker commit -m="has update" -a="author" container-ID image-NAME:TAG

    # 方式2 使用Dockerfile指令来构建一个镜像
    cat Dockerfile
    ---
    FROM centos:6.7
    MAINTAINER Fisher "fisher@163.com"

    RUN /bin/echo 'root:12345' | chpasswd
    RUN useradd tom
    RUN /bin/echo 'tom:12345' | chpasswd
    RUN /bin/echo -e "LANG=\"en_US.UTF-8"" > /etc/default/local
    EXPOSE 22
    EXPOSE 80
    CMD /usr/sbin/sshd -D
    ---
    docker build -t tom/centos:6.7 .
    #-t 指定要创建的镜像名
    # . Dockerfile所在目录

    #设置镜像标签
    docker tag image-ID tom/centos:dev #多了一个新标签
  • 容器使用

    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    #查看Docker客户端的所有命令选项
    docker
    #了解指定docker命令
    docker stats --help

    #启动容器
    docker run -it ubuntu /bin/bash
    #-i 交互式操作
    #-t 终端
    #ubuntu 镜像
    #/bin/bash 交互的shell
    docker run -itd --name ubuntu-test ubuntu /bin/bash
    #-d 后台运行

    #查看容器
    docker ps -a
    #-a 查看所有的容器,包括停止的容器

    #启动一个容器
    docker start container-ID/NAME
    #停止一个容器
    docker stop container-ID/NAME
    #重启一个容器
    docker restart container-ID/NAME

    #进入容器
    docker attach container-ID/NAME
    #exit后 容器停止
    docker exec -it container-ID/NAME /bin/bash
    #exit后 容器不停止

    #导入和导出容器
    docker export container-ID/NAME > ubuntu.tar
    cat ubuntu.tar | docker import - test/ubuntu:v1

    #删除一个容器
    docker rm -f container-ID/NAME

    #运行一个web应用
    docker pull training/webapp
    docker run -d -P training/webapp python app.py
    #-P 将容器内部使用的网络端口随机映射到我们使用的主机上
    docker pull nginx
    docker run -d -p 8080:80 --name nginx-test nginx:latest
    #-p 8080:80 指定端口映射 主机8080 容器80

    #查看网络端口映射
    docker port container-ID/NAME
    #查看WEB应用日志
    docker logs -f container-ID/NAME
    #查看WEB应用程序的进程
    docker top container-ID/NAME
    #检查WEB应用程序
    docker inspect container-ID/NAME
  • 容器连接

    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
    #网络端口映射
    docker run -d -P image-ID/NAME
    docker run -d -p 8080:80 --name container-NAME image-ID/NAME
    docker run -d -p 127.0.0.1:80 image-ID/NAME
    #默认tcp端口
    docker run -d -p 127.0.0.1:5000:5000/udp image-ID

    #容器互联
    #新建网络
    docker network create -d bridge test-net
    #-d 指定网络类型 bridge 桥接 /overlay
    docker run -itd --name test1 --network test-net ubuntu /bin/bash
    docker run -itd --name test2 --network test-net ubuntu /bin/bash
    #容器 test1中 能直接 ping test2

    #配置DNS
    #所有的容器
    vim /etc/docker/daemon.json
    ---
    {
    "dns":[
    "114.114.114.114",
    "8.8.8.8"
    ]
    }
    ---
    #指定容器DNS
    docker run -it --rm -h host_ubuntu --dns=114.114.114.114 --dns-search=test.com ubuntu
    #--rm 容器退出时,自动清理容器内部的文件系统
    #-h HOSTNAME 设定容器的主机名
    #--dns=IP_ADDRESS 添加DNS服务器
    #--dns-search=DOMAIN 设定容器的搜索域
  • 仓库管理

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    #DOCKER 官方仓库Docker Hub https://hub.docker.com 免费注册一个Docker账号
    #登录和退出
    docker login
    docker logout
    #搜索官方仓库中的镜像
    docker search ubuntu
    #拉取镜像
    docker pull ubuntu
    #推送镜像
    docker push NAME:TAG

hexo-study

hexo

  • 安装

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    #安装nodejs
    sudo pacman -S nodejs
    sudo pacman -S npm

    #安装hexo-cli hexo-deployer-git
    sudo npm install -g hexo-cli
    sudo npm install hexo-deployer-git --save

    #安装git
    sudo pacman -S git
  • 准备

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    #初始化
    mkdir blog
    hexo init blog

    #安装依赖
    cd blog
    npm install

    #本地服务
    hexo server

    #访问localhost:4000 见 页面
  • 配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    vim _config.yml
    ---
    #修改
    title author
    repo: https://your_github_name:access-token@gihub.com/your_name/github.io.git
    branch: main
    --

    github.com 自己仓库 开启pages
  • 上传

    1
    2
    3
    4
    5
    6
    7
    hexo clean

    #产生public目录 及 其下文件
    hexo g

    #上传到仓库
    hexo d