Ubuntu 常用命令
修改时间(重启不失效)
timedatectl set-timezone Asia/Shanghai
修改时间(重启不失效)
timedatectl set-timezone Asia/Shanghai
array = ['', '33', '44']
s = [x for x in array if x]
# print:['33', '44']
ALTER DATABASE db_name DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
INSERT INTO newtableName(col1, col2) SELECT column1, 'somevalue' as column2 FROM tableName;
# 更新全部可更新软件包,包含OpenWRT内核等
opkg list-upgradable | cut -f 1 -d ' ' | xargs opkg upgrade
find . -type f -exec mv {} /home/jack \;
sudo curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh
sudo bash install-release.sh
sudo systemctl enable v2ray
sudo systemctl restart v2ray
config path:
/usr/local/etc/v2ray/config.json
{
"inbounds": [
{
"port": 1080,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "xxxxxxxxxxxxxxxxxxxxxxxxx"
}
]
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}
sudo mdutil -i off /(该命令用来关闭索引)
sudo mdutil -E /(该命令用来删除索引)
sudo mdutil -i on /(该命令用来重建索引)
要自己搭建SSR服务器,您需要遵循以下步骤:
准备工作:
购买一台VPS(虚拟专用服务器),推荐使用腾讯云、阿里云、华为云等云服务提供商。
安装Linux操作系统,推荐使用Ubuntu或Debian。
配置服务器的基本环境,包括SSH登录、防火墙设置等。
安装Shadowsocks:
使用以下命令安装Shadowsocks:apt-get update
apt-get install python-pip
pip install shadowsocks
创建Shadowsocks配置文件,例如/etc/shadowsocks.json,并填写以下内容:{
"server": "0.0.0.0",
"server_port": 8388,
"local_address": "127.0.0.1",
"local_port": 1080,
"password": "your_password",
"timeout": 300,
"method": "aes-256-cfb"
}
启动Shadowsocks服务:ssserver -c /etc/shadowsocks.json -d start
安装ShadowsocksR:
使用以下命令安装ShadowsocksR:apt-get install python-pip
pip install git+https://github.com/shadowsocksr-backup/shadowsocksr.git@master
创建ShadowsocksR配置文件,例如/etc/shadowsocksr.json,并填写以下内容:{
"server": "0.0.0.0",
"server_port": 8388,
"local_address": "127.0.0.1",
"local_port": 1080,
"password": "your_password",
"timeout": 300,
"method": "aes-256-cfb",
"protocol": "auth_aes128_md5",
"protocol_param": "",
"obfs": "tls1.2_ticket_auth",
"obfs_param": ""
}
启动ShadowsocksR服务:ssr -c /etc/shadowsocksr.json -d start
配置防火墙:
使用以下命令打开服务器的8388端口:ufw allow 8388/tcp
启用防火墙:ufw enable
测试SSR服务器:
使用Shadowsocks客户端连接到您的SSR服务器,并进行基本的网络连接测试。
配置自动启动:
使用以下命令配置ShadowsocksR服务自动启动:systemctl enable ssr
apt update
apt install ca-certificates curl gnupg lsb-release
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
apt update
apt install docker.io
apt install docker-compose
ipset flush gfwlist
高配置的电脑,编译更快,毫无疑问
1、 先把 openwrt
源码克隆到本地
https://gitee.com/harvey520/openwrt.git
每天自动从官方源拉取更新一次,不会存在更新不及时问题
git clone https://gitee.com/harvey520/openwrt.git
2、修改 openwrt
源码目录的 feeds.conf.default
文件中的镜像源
https://git.openwrt.org/feed/packages.git
改为 https://gitee.com/harvey520/packages.git
https://git.openwrt.org/project/luci.git
改为 https://gitee.com/harvey520/luci.git
https://git.openwrt.org/feed/routing.git
改为 https://gitee.com/harvey520/routing.git
https://git.openwrt.org/feed/telephony.git
改为 https://gitee.com/harvey520/telephony.git
https://gitee.com/harvey520
中的镜像源每天自动从官方源更新一次,不会存在过期或更新不及时问题
3、提前下载依赖库源码放到 openwrt
源码目录中
国内惟一仓库,只此一家,别无分号
进入 openwrt
源码目录中,执行以下命令
git clone https://e.coding.net/yao7778899/openwrt-dependent-dl.git dl
# 依赖库源码总计约850M
4、开始你的编译
执行以下命令开始你的编译,能够多快就看你家的宽带有多快了
./scripts/feeds update -a
./scripts/feeds install -a
make V=99
Python中,字典(dict) 是一种内置的映射类型,也是惟一的;字典由键及其相应的值组成,这种键-值对
称为项(item)。
dict1 = {} # 空字典
# python 是完全动态数据类型,同一个字典Value类型可以是多种的
dict2 = {'name': 'python3.7', 'age': 19, 'website': 'http://www.python.org'}
print(dict2) # {'name': 'python3.7', 'age': 19, 'website': 'http://www.python.org'}
length = len(dict2)
print(length) # 3
del dict2['website'] # 通过key删除项
# dict2.clear() # 删除掉所有项
print(dict2) # {'name': 'python3.7', 'age': 19}
dict2['website'] = 'http://www.python.org'
print(dict2) # {'name': 'python3.7', 'age': 19, 'website': 'http://www.python.org'}
dict2['website'] = 'http://python.org' # 通过key修改值
print(dict2) # {'name': 'python3.7', 'age': 19, 'website': 'http://python.org'}
website = dict2['website'] # 通过 key 获取值
print(website) # http://python.org
keys = dict2.keys()
print(keys) # dict_keys(['name', 'age', 'website'])
# 排序后获取到的是list
keys = sorted(dict2.keys())
print(keys) # ['age', 'name', 'website']
values = dict2.values()
print(values) # dict_values(['python3.7', 19, 'http://python.org'])
if 'mykey' in dict2:
print('字典中存在 `mykey`')
if 'mykey' not in dict2:
print('字典中不存在 `mykey`')
# 遍历 key
for key in dict2:
value = dict2[key]
print(key, value)
# 遍历 value
for value in dict2.values():
print(value)
# format_map 会自动查找与参数名一样的key,并获取值
desc = 'python home is {website}'.format_map(dict2)
print(desc) # python home is http://python.org
desc = '{name} home is {website}'.format_map(dict2)
print(desc) # python3.7 home is http://python.org
在 Python 中常用的序列是列表(List)和元组(Tuple),列表(List)是 Python 的主力序列;这两者的区别:列表(List)是可修改的,元组(Tuple)是不可修改的。Python中的序列是很强大的,可以进行切片(本方只介绍简单切片)、相加、相乘等操作。
切片(slicing):访问特定范围内的元素
切片格式:list[开始索引(包括):结束索引(不包括)]
索引可以是正索引或负索引,负索引从最后以 -1
开始往前标识
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
numbers_slicing = numbers[3:5]
print(numbers_slicing) # [4, 5]
numbers_slicing = numbers[:3] # 开始索引默认为0
print(numbers_slicing) # [1, 2, 3]
numbers_slicing = numbers[3:] # 结束索引默认为最后一个索引
print(numbers_slicing) # [4, 5, 6, 7, 8, 9, 10]
numbers_slicing = numbers[:-3] # -3 为倒数的第三个索引
print(numbers_slicing) # [1, 2, 3, 4, 5, 6, 7]
numbers1 = [1, 2, 3, 4]
numbers2 = [5, 6, 7]
numbers = numbers1 + numbers2
print(numbers) # [1, 2, 3, 4, 5, 6, 7]
numbers1 = [1, 2, 3, 4]
string = ['hello', 'world']
listall = numbers1 + string
print(listall) # [1, 2, 3, 4, 'hello', 'world']
string = 'python' * 10
print(string) # pythonpythonpythonpythonpythonpythonpythonpythonpythonpython
numbers = [1, 2] * 3
print(numbers) # [1, 2, 1, 2, 1, 2]
# None、空列表和初始化
sequence = [None] * 10
print(sequence) # [None, None, None, None, None, None, None, None, None, None]
list1 = ['hello', 'python']
if 'python3.7' not in list1:
print('list1 元素中不存在 `python3.7`')
if 'python' in list1:
print('list1 元素中存在 `python`')
array = ['hi', 'python', 2020]
for item in array:
print(item)
'''
hi
python
2020
'''
# 带索引遍历
for index, item in enumerate(array):
print(index, item)
'''
0 hi
1 python
2 2020
'''
元组(Tuple) 是 Python 中常用的序列,它是不可修改的。
tuple1 = ()
tuple2 = ('hello', 'python')
tuple3 = ('hello', 'python', 2020) # python 是完全动态数据类型,同一个元组元素类型可以是多种的
print(tuple1) # ('hello', 'python')
length = len(tuple2)
print(length) # 2
numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
numbers_slicing = numbers[3:5]
print(numbers_slicing) # (4, 5)
numbers1 = (1, 2, 3, 4)
numbers2 = (5, 6, 7)
numbers = numbers1 + numbers2
print(numbers) # (1, 2, 3, 4, 5, 6, 7)
numbers = (1, 2) * 3
print(numbers) # (1, 2, 1, 2, 1, 2)
列表(List)是 Python 中常用的序列,它是 Python 的主力序列,它是可修改的。
list1 = []
list2 = ['hello', 'python']
list3 = ['hello', 'python', 2020] # python 是完全动态数据类型,同一个列表元素类型可以是多种的
print(list2) # ['hello', 'python']
length = len(list2)
print(length) # 2
list2.remove('python') # 删除元素
# del list2[1] # 通过下标删除元素
print(list2) # ['hello']
list1.append('2020') # 追加一个元素
print(list1) # ['2020']
list3[1] = 'world' # 通过索引修改元素值
print(list3) # ['hello', 'world', 2020]
(list3[0], list3[1]) = (list3[1], list3[0])
print(list3) # ['world', 'hello', 2020]
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
numbers_slicing = numbers[3:5]
print(numbers_slicing) # [4, 5]
numbers1 = [1, 2, 3, 4]
numbers2 = [5, 6, 7]
numbers = numbers1 + numbers2
print(numbers) # [1, 2, 3, 4, 5, 6, 7]
numbers = [1, 2] * 3
print(numbers) # [1, 2, 1, 2, 1, 2]
string = ''
string1 = 'this is a string'
string2 = r'this is a raw string' # 原始字符串, 转义字符等均不转义原样输出
length = len(string1)
print(length) # 16
if 'is' in string1:
print('string1 含有 `is`')
if string1 == string2:
print('string1 与 string2 一样')
n_str = 'this is ' + 'a string' # 使用 `+` 拼接
print(n_str) # this is a string
n_str = 'this is '
n_str += 'a string' # 使用 `+=` 拼接
print(n_str) # this is a string
n_str2 = 'num: ' + str(4) # 拼接数字
print(n_str2) # num: 4
format_str = '%s is a string. length: %d'%('this', 16) # 格式化, %f、%d、%s等格式, 和 C 语言基本上一致
print(format_str) # this is a string. length: 16
format_str = 'th{} {p1} a {p2}'.format('is', p2='string', p1='is')
# format_str = 'th{p1} {p1} a {p2}'.format(p2='string', p1='is')
# format_str = 'th{1} {1} a {0}'.format('string', 'is')
# format_str = '{0} is a {1}'.format('this', 'string')
# format_str = '{} is a {}'.format('this', 'string')
print(format_str) # this is a string
t_str = 'The number is {num}'.format(num=88)
print(t_str) # The number is 88
t_str = 'The number is {num:f}'.format(num=88) # 浮点型
print(t_str) # The number is 88.000000
t_str = 'The number is {num:.2f}'.format(num=88) # 浮点型-保留2位小数
print(t_str) # The number is 88.00
t_str = 'The number is {num:010.2f}'.format(num=88) # 浮点型-保留2位小数,指定宽度, 如果不足则在前面补0
print(t_str) # The number is 0000088.00
t_str = 'The number is {num:b}'.format(num=88) # 二进制
print(t_str) # The number is 1011000
python 分正索引与负索引, 正索引和其他编程语言一样;负索引是从最后往前标识, 负索引是从-1
开始的
切片格式:str[截取开始索引:截取结束索引]
t_str = string1[:-3] # 从索引0开始截取到倒数第三个字符之前的位置
# t_str = string1[0:-3]
print(t_str) # This is a str
t_str = string1[:3] # 从索引0开始截取到索引3字符之前的位置
# t_str = string1[0:3]
print(t_str) # Thi
t_str = string1[5:7] # 从索引5开始截取到索引7之前的位置
print(t_str) # is
array = string1.split(' ') # 以空格分割字符串
print(array) # ['This', 'is', 'a', 'string']
t_str = '-'.join(array) # 以 `-` 将字符串数组拼接成字符串
print(t_str) # This-is-a-string
upp = string1.upper() # 转为大写
print(upp) # THIS IS A STRING
low = upp.lower() # 转为小写
print(low) # this is a string
t_str = ' \n\n this is a string \n'.strip()
print(t_str) # this is a string
index = string1.find('is a') # 如果查找到子字符串则返回子串的第一个字符的索引,否则返回 `-1`
print(index) # 5
t_str = string1.replace('string', 'raw string')
print(t_str) # This is a raw string
for char in string1:
print(char)
'''
T
h
i
s
i
s
a
s
t
r
i
n
g
'''
#!/usr/local/bin/python3.7
# coding=utf-8
import math
import random
import subprocess
print('Hello Python')
# 除法 结果为小数
num = 11 / 2
print(num) # 5.5
# 除法 舍弃小数部分,向下取整数
num = 10 // 3
print(num) # 3
# 除法 舍弃小数部分,向下取整数
num = 10 // -3
print(num) # -4
# 求余 - 整数
num = 10 % 3
print(num) # 1
# 小数求余
num = 10 % 3.5
print(num) # 3.0
# 小数求余
num = 10.3 % 3.5
print(num) # 3.3000000000000007
# 幂运算符
# 2的3次方
num = 2 ** 3
print(num) # 8
# 幂运算函数
# 2的3次方
num = pow(2, 3) # 8
print(num)
# 十六进制数表示:0x
num = 0x0af
print(num) # 175
# 八进制数表示:0o
num = 0o10
print(num) # 8
# 二进制数表示:0b
num = 0b000010
print(num) # 2
# 取整数
print(math.floor(32.9)) # 32
# 有小数有进一
print(math.ceil(32.9)) # 33
# 平方根
print(math.sqrt(9)) # 3.0
# 调用 shell 命令
subprocess.call('ls -a', shell=True)
subprocess.call('mkdir myFoloder', shell=True)
# 字符串
string1 = "let's go c:\bbb\bccc"
string2 = r"let's go c:\bbb\bccc" # 原始字符串, 原样输出
print(string1) # let's go cbccc
print(string2) # let's go c:\bbb\bccc
# 产生随机数,包含边界即1和3
num = random.randint(1,3) # 可能随机数:1, 2, 3
print(num)
# 列表(相当于其他编程语言的数组)
mylist = [29 ,39, 49]
random.shuffle(mylist) # 随机打乱列表的排列
mylist.reverse() # 将列表逆序, [49, 39, 29]
print(random.choice(mylist)) # 随机从列表获取一个元素