Skip to content

Commit

Permalink
update db
Browse files Browse the repository at this point in the history
  • Loading branch information
qv-china committed Jun 29, 2024
1 parent f3c9465 commit 5a01a01
Show file tree
Hide file tree
Showing 14 changed files with 3,059 additions and 3 deletions.
14 changes: 12 additions & 2 deletions linux_cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ void displayCommandWithNewlines(const std::string& command) {
int main(int argc, char *argv[]) {
if (argc==1)
{
std::cout << "缺少参数. cmd fhq " << std::endl;
return 1 ;
std::ifstream file("readme");
if (file.is_open()) {
std::string line;
while (std::getline(file, line)) {
std::cout << line << std::endl;
}
file.close();
} else {
std::cerr << "无法打开文件readme" << std::endl;
return 1;
}
return 0;
}
char buff[PATH_MAX];
std::string argName = argv[1];
Expand Down
6 changes: 6 additions & 0 deletions linux_cmd/fhq
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ systemctl enable firewalld && systemctl is-enabled firewalld
禁止防火墙开机启动
1
systemctl disable firewalld && systemctl is-enabled firewalld
防火墙配置文件目录
0
cd /etc/firewalld/zones
禁止ip访问指定协议指定端口
0
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.1" port protocol="tcp" port="6379" reject"
6 changes: 6 additions & 0 deletions linux_cmd/file
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
查询大于1G大小的文件
1
find / -type f -size +1G
查询home目录大小
0
du -sh /home
2 changes: 1 addition & 1 deletion linux_cmd/wl → linux_cmd/net
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
查看网络连接
查看本地监听端口,服务,对应pid,程序名
1
netstat -tnlp
谁连我
Expand Down
6 changes: 6 additions & 0 deletions linux_cmd/readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
命令格式如下:
cmd fhq 防火墙
cmd net 网络
cmd tmux tmux
cmd file 文件目录

39 changes: 39 additions & 0 deletions linux_cmd/scan_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# 检查命令是否存在并打印软件包管理器名称
check_command() {
if command -v $1 &> /dev/null; then
echo "$2 is available"
exit 0
fi
}

# Check for common package managers
check_command apt "APT (Debian, Ubuntu)"
check_command apt-get "APT (Debian, Ubuntu)"
check_command yum "YUM (CentOS, RHEL)"
check_command dnf "DNF (Fedora, RHEL 8+)"
check_command rpm "RPM (CentOS, RHEL, Fedora, SUSE)"
check_command pacman "Pacman (Arch Linux)"
check_command zypper "Zypper (openSUSE, SLES)"
check_command eopkg "EOPKG (Solus)"
check_command snap "Snap (Cross-distribution)"
check_command flatpak "Flatpak (Cross-distribution)"
check_command opkg "OPKG (OpenWrt, embedded systems)"
check_command pkg "PKG (FreeBSD)"
check_command apk "APK (Alpine Linux)"
check_command xbps-install "XBPS (Void Linux)"
check_command swupd "swupd (Clear Linux)"
check_command pkgutil "pkgutil (Solaris, Illumos)"
check_command pkg_add "pkg_add (OpenBSD)"
check_command yast "YaST (SUSE Linux Enterprise)"
check_command equo "Equo (Sabayon Linux)"
check_command emerge "Portage (Gentoo)"
check_command nix-env "Nix (NixOS)"
check_command guix "Guix (GuixSD)"
check_command ups "UPS (Unified Package System, Oracle Solaris)"

# 如果没有找到公共包管理器
echo "No common package manager found"
exit 1

27 changes: 27 additions & 0 deletions linux_cmd/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <string>

std::string replaceBracketedContent(const std::string& input) {
std::string output = input;
size_t startPos = 0;
while ((startPos = output.find('[', startPos))!= std::string::npos) {
size_t endPos = output.find(']', startPos);
if (endPos == std::string::npos) {
break;
}
std::string key = output.substr(startPos + 1, endPos - startPos - 1);
std::cout << "请输入 " << key << ": ";
std::string value;
std::cin >> value;
output.replace(startPos, endPos - startPos + 1, value);
startPos = endPos + value.size();
}
return output;
}

int main() {
std::string input = "firewall-cmd --permanent --add-rich-rule=\"rule family=\"ipv4\" source address=\"[ip]\" port port=\"[port]\" protocol=\"tcp\" accept\"";
std::string output = replaceBracketedContent(input);
std::cout << output << std::endl;
return 0;
}
99 changes: 99 additions & 0 deletions linux_cmd/wincmd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <windows.h>

// 定义一个结构体来存储每行的信息
struct CommandInfo {
std::string description;
int flag;
std::string command;
};

void displayCommandWithNewlines(const std::string& command) {
for (size_t i = 0; i < command.size() - 1; ++i) {
if (command[i] == '\\' && command[i + 1] == 'r') {
std::cout << std::endl;
++i; // 跳过第二个 '\r'
} else {
std::cout << command[i];
}
}
std::cout << command.back() << std::endl; // 输出最后一个字符
}

int main(int argc, char *argv[]) {
if (argc == 1) {
std::ifstream file("readme.txt"); // Windows 上更常用 ".txt" 扩展名
if (file.is_open()) {
std::string line;
while (std::getline(file, line)) {
std::cout << line << std::endl;
}
file.close();
} else {
std::cerr << "无法打开文件 readme.txt" << std::endl;
return 1;
}
return 0;
}

char buff[MAX_PATH];
std::string argName = argv[1];
std::string output = std::string(getenv("USERPROFILE")) + "\\cmd\\" + argName;
std::list<CommandInfo> commandList;
std::ifstream file(output); // 替换为实际的文件名

if (!file.is_open()) {
std::cerr << "无法打开文件" << std::endl;
return 1;
}

std::string line;
int lineCount = 1;
CommandInfo info;
int sequenceNumber = 1; // 序列号

while (std::getline(file, line)) {
switch (lineCount) {
case 1:
info.description = line;
break;
case 2:
info.flag = std::stoi(line); // 将字符串转换为整数
break;
case 3:
info.command = line;
commandList.push_back(info);
std::cout << sequenceNumber << ". " << info.description << std::endl;
sequenceNumber++;
lineCount = 0;
break;
}
lineCount++;
}

file.close();

int choice;
std::cout << "请输入要执行的序列号: ";
std::cin >> choice;

auto it = commandList.begin();
std::advance(it, choice - 1); // 将迭代器移动到用户选择的位置

if (choice == 0 && it != commandList.end()) {
displayCommandWithNewlines(it->command);
} else if (it != commandList.end()) {
if (it->flag == 1) {
std::system(it->command.c_str()); // 在 Windows 下执行命令
} else {
std::cout << it->command << std::endl; // 在屏幕上显示命令
}
} else {
std::cout << "无效的序列号" << std::endl;
}

return 0;
}
4 changes: 4 additions & 0 deletions vim配置/.vim/.netrwhist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let g:netrw_dirhistmax =10
let g:netrw_dirhistcnt =2
let g:netrw_dirhist_2='/root/.vim'
let g:netrw_dirhist_1='/etc/NetworkManager/system-connections'
Loading

0 comments on commit 5a01a01

Please sign in to comment.