跳转到内容

博客

VM CPP QT编译环境与VSCode


标签: - 菲律宾共产党 - VS代码类别: - Linux日期:创建时间:2022-12-30# 更新时间:2024-01-19—

(1).安装了 Visual Studio Code首先,应在一台运行 Windows/Linux/MacOS 的 PC 上安装最新版本的 VSCode。

Section titled “(1).安装了 Visual Studio Code首先,应在一台运行 Windows/Linux/MacOS 的 PC 上安装最新版本的 VSCode。”

其次,应安装以下扩展: [C/C++] [远程SSH] [远程 SSH:编辑配置文件]

(2)。安装了 VMWare Workstation,并配置了虚拟机。

Section titled “(2)。安装了 VMWare Workstation,并配置了虚拟机。”

首先,虚拟机要正常运行。 此外,网络也正常(从主机 PING 到虚拟机,反之亦然)。

(1).配置“SSH 目标”打开“REMOTE EXPLORER”窗口 -> “Add NEW”,然后在对话框中键入以下命令:

Section titled “(1).配置“SSH 目标”打开“REMOTE EXPLORER”窗口 -> “Add NEW”,然后在对话框中键入以下命令:”

ssh USER@192.xxx.xxx.xxx -A 输入密码并将弹出选项保留为默认值。

USER是虚拟机用户名的用户> 192.xxx.xxx.xxx是虚拟机的 IP 地址。 然后选择合适的路径作为编译默认路径,推荐使用Home路径。

(2)。将源代码上传到虚拟机在这一步中,可以应用许多工具,包括scp、sftp、xshell。

Section titled “(2)。将源代码上传到虚拟机在这一步中,可以应用许多工具,包括scp、sftp、xshell。”

注意!您应该使用正确的用户上传代码以避免权限错误。

3.VSCode配置步骤1.在VSCode中打开源代码路径。

Section titled “3.VSCode配置步骤1.在VSCode中打开源代码路径。”

步骤2。如果不存在这样的目录,请添加一个名为.vscode的新目录。

(1). CPP配置在.vscode文件夹中添加c_cpp_properties.json。内容如下:

Section titled “(1). CPP配置在.vscode文件夹中添加c_cpp_properties.json。内容如下:”
{
"configurations": [
{
"name": "RHEL7.2->Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/scadacom/current/**"
],
"forcedInclude": [],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [ //Release
"-std=c++11",
"-w",
"-O2",
"-pipe",
"-m64",
"-D_REENTRANT",
"-DQT_SHARED",
"-DQT_NO_DEBUG_OUTPUT",
"-DQT_NO_DEBUG",
"-DQT_GUI_LIB",
"-DQT_NETWORK_LIB",
"-DQT_CORE_LIB",
"-DQT_SHARED"
]
},
{
"name": "RHEL7.2-WindowsLocal",
"includePath": [
"${workspaceFolder}/**",
"~/Documents/Codes/include/RHEL7.2S5.8.10/**",
"C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include"
],
"forcedInclude": [],
"defines": [],
"compilerPath": "C:/ProgramData/chocolatey/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [ //Release
"-std=c++11",
"-w",
"-O2",
"-pipe",
"-m64",
"-D_REENTRANT",
"-DQT_SHARED",
"-DQT_NO_DEBUG_OUTPUT",
"-DQT_NO_DEBUG",
"-DQT_GUI_LIB",
"-DQT_NETWORK_LIB",
"-DQT_CORE_LIB",
"-DQT_SHARED"
],
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/**",
"~/Documents/Codes/include/RHEL7.2S5.8.10/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}

(2)。构建任务配置Qmake 和 g++ 编译配置需要在tasks.json文件中配置。内容如下:

Section titled “(2)。构建任务配置Qmake 和 g++ 编译配置需要在tasks.json文件中配置。内容如下:”
{
"version": "2.0.0",
// "windows": {
// "options": {
// "shell": {
// "executable": "bash.exe",
// "args": ["-c"]
// }
// }
// },
"tasks": [
{
"label": "Qmake",
"type": "shell",
"command": "/usr/local/Trolltech/Qt-4.8.4/bin/qmake",
"args": [],
"group": "build",
"presentation": {
"reveal": "silent",
"clear": true
}
},
{
"label": "Clean",
"type": "shell",
"command": "make",
"args": [
"clean"
],
"group": "build",
"presentation": {
"reveal": "silent",
"clear": true
}
},
{
"label": "MakeCompile",
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"Clean",
"Qmake"
],
"command": "/usr/bin/make",
"args": [
],
"group": "build",
"presentation": {
// "reveal": "silent",
"clear": true
}
},
]
}

配置任务后,您可以通过按CTRL+Shift+B从 vscode 编辑窗口启动构建任务。 说明书如下:>Qmake: 运行命令/usr/local/Trolltech/Qt-4.8.4/bin/qmake>

Release: 自动运行Qmake后运行命令/usr/bin/make -f Makefile.Release。> Debug: 自动运行Qmake后运行命令/usr/bin/make -f Makefile.Debug。> Clean: 删除 Qmake 和 g++ 生成的文件> Clean-Release: 运行命令make -f Makefile.Release clean> Clean-Debug: 运行命令make -f Makefile.Debug clean

(3)。调试配置GNU gdb 工具将用作调试工具,您可以使用以下launch.json配置来调试代码:

Section titled “(3)。调试配置GNU gdb 工具将用作调试工具,您可以使用以下launch.json配置来调试代码:”
{
"version": "0.2.0",
"configurations": [
{
"name": "QT-CPPGDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/wg_modbus_ats",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/debug/",
"environment": [],
//"symbolSearchPath": "C:\\Symbols",
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"miDebuggerPath": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi",
"MIMode": "lldb"
},
// "logging": {
// "moduleLoad": false,
// "trace": true
// },
"visualizerFile": "my.natvis"
},
{
"name": "CMake-CPPGDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/${workspaceFolderBasename}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
//"symbolSearchPath": "C:\\Symbols",
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"miDebuggerPath": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi",
"MIMode": "lldb"
},
// "logging": {
// "moduleLoad": false,
// "trace": true
// },
"visualizerFile": "my.natvis"
}
]
}

但是,调试不能自动更改目标,调试流程应如下: 运行Clean或Clean-Debug-> 运行Debug-> 更改TARGETS-> 设置断点 -> 按F5。

TARGETS是 g++ 生成的可执行文件。 所有配置文件都可以在[此处]找到。

[2]. [C/C++] [3]. [远程SSH] [4]. [远程 SSH:编辑配置文件] [5]. VSCode-C-CPP-环境 [6]. Qmake-Pro [远程 SSH]:https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh[C/C++]:https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools[远程 SSH:编辑配置文件]:https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh-edit[这里]:https://gitlab.dashdreams.com:8443/Haoran.Qi/include/-/tree/master/.vscode

使用 ShellScript 自动归档文件


标签: - 壳类别: - Linux日期:# 创建时间:2025-03-27# 更新时间:2024-01-19—

一、简介我们将介绍一个 shell 脚本,它可以在 Linux 上自动归档文件夹。

Section titled “一、简介我们将介绍一个 shell 脚本,它可以在 Linux 上自动归档文件夹。”

2. 环境要求- 操作系统:带 SHELL(sh) 的 Linux,也可能是其他 Unix。- bash:Linux bash。

Section titled “2. 环境要求- 操作系统:带 SHELL(sh) 的 Linux,也可能是其他 Unix。- bash:Linux bash。”

3. 脚本该脚本可以自动将配置的文件夹返回到配置的目的地:

Section titled “3. 脚本该脚本可以自动将配置的文件夹返回到配置的目的地:”
################################ Global Config #################################
# Source Folder
__SERVICE_SOURCE__="${HOMEDIR}"
# Local Backup Folder
__HDD_PACK_BACK__="${HDD_BASE}"
__LOCAL_CLOUD_OD__="${HOMEDIR}/BackUp"
################################ Global Config #################################
################################# Service ######################################
declare -A SERVICES=(
["services"]="${__SERVICE_SOURCE__}/services,${LOGPATH}/services.log"
)
################################# Service ######################################
# log 1:MSG [2:LOG_PRITORITY]
log()
{
__log_time__=$(date +"%b %e %T")
if [ "${#}" -lt 1 ]; then
false
else
__log_msg__="${1}"
fi
if [ "${#}" -lt 2 ]; then
__log_prio__=7
else
__log_prio__=${2}
fi
logger -p ${__log_prio__} -t "$(basename ${0})" "${__log_msg__}"
echo "${__log_time__} $(basename ${0}) (${__log_prio__}): ${__log_msg__}" >> ${__LOGFILE__}
}
# Encrypter 1:SOURCE_FILE 2:DEST_FOLDER [3:RECEIVER]
Encrypter()
{
__receiver__="xxxxxxxxxxxxxxxx"
if [ "${#}" -lt 2 ]; then
false
elif [ "${#}" -eq 3 ]; then
__receiver__=${3}
fi
__encrypt_file__=${2}/${1##*/}.gpg
log "dest encrypt file: ${__encrypt_file__}"
# Delete exist NOT Uploaded file
if [ -e ${__encrypt_file__} ]; then
rm ${__encrypt_file__}
log "Deleted exist file: ${__encrypt_file__} ......Done"
fi
# Encrypting packed files to DEST_FOLDER
gpg -e -r ${__receiver__} -o ${__encrypt_file__} ${1}
if [ -e ${__encrypt_file__} ]; then
log "Encrypted...... ${__encrypt_file__} to __LOCAL_CLOUD_OD__ ......Done"
fi
}
# Packer 1:SOURCE_FOLDER(whole path) 2:PACKED_DEST_FOLDER [3:ENCRYPT_DEST_FOLDER]
# If only use first 2 parameters, will not encrypt;
# If you wish to encrypt, you should use all 3 parameters.
Packer()
{
# if end without "/"
__service_name__=${1##*/}
# if end with "/"
if [[ ${__service_name__} == "" ]]; then
__service_name__="${1%%/}"
__service_name__="${__service_name__##*/}"
fi
__tar_file__=${2}/${__service_name__}_$(date "+%Y%m%d").tar.gz
# Packing
if [ ! -e ${__tar_file__} ]; then
# Packing folder
tar -zcvf ${__tar_file__} ${1}
log "Packed up ${__tar_file__} ......Done"
# Encrypt from PACKED_DEST_FOLDER to ENCRYPT_DEST_FOLDER
if [ -e ${__tar_file__} ]; then
log "Save NOT encrypt file: ${__tar_file__} ......Done"
# Check if need encryption
if [ "${#}" -eq 3 ]; then
Encrypter ${__tar_file__} ${3}
fi
fi
fi
}
# PersonalFileBackUper 1:SOURCE_FOLDER 2:LOG_FILE
PersonalFileBackUper()
{
__LOGFILE__=${2}
# Pack BackUp and Cloud BackUp
if [ $(date "+%d") == "01" ]; then
Packer ${1} ${__HDD_PACK_BACK__} ${__LOCAL_CLOUD_OD__}
else
Packer ${1} ${__HDD_PACK_BACK__}
fi
}
# CleanOldTarBackup 1:SERVICE_NAME
CleanOldTarBackup()
{
__backup_versions__=$(ls -l ${__HDD_PACK_BACK__}/*${1}* | wc -l)
if [ ${__backup_versions__} -gt 1 ]; then
find ${__HDD_PACK_BACK__} -name "*${1}*" -mtime +6 -mtime -30 -exec rm {} \;
__reserve_vers__=$(ls -l ${__HDD_PACK_BACK__}/*${1}* | wc -l)
if [ ${__backup_versions__} -ne ${__reserve_vers__} ]; then
log "Delete Old Backup files......Done"
fi
fi
}
main()
{
# Backup Personal Service Data
for service in "${!SERVICES[@]}"
do
{
PersonalFileBackUper "${SERVICES[$service]%,*}" "${SERVICES[$service]#*,}"
log "Archive ${service} OK."
sleep 1
# CleanUp Old Backup
CleanOldTarBackup "${service}"
sleep 1
}
done
}
# Calling main() funcion
main
[Unit]
Description=Backup files automatically
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
WorkingDirectory=/home/$USER
Environment="HOMEDIR=/home/$USER"
Environment="HDD_BASE=/Path/To/SSD"
Environment="LOGPATH=/var/log/ArchiveBackUp"
ExecStart=/bin/bash /Path/To/Script/ArchiveBackUp.sh
[Install]
WantedBy=multi-user.target

一些环境应该在上面的服务文件中配置:- 主目录- 硬盘_基础- 日志路径

[2].Shell字符串截取

在 RHEL 上使用 Nginx 进行反向代理


标签: - nginx类别: - 网络日期:创建时间:2024-01-17# 更新时间:2024-01-19—

在 RHEL 上使用 Nginx 进行反向代理

Section titled “在 RHEL 上使用 Nginx 进行反向代理”

介绍本文介绍了一种在 RHEL 上使用 Nginx Web 服务器进行反向代理的方法。

Section titled “介绍本文介绍了一种在 RHEL 上使用 Nginx Web 服务器进行反向代理的方法。”
sudo dnf install nginx
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}

(2)。/etc/nginx/conf.d/*.conf中的站点配置

Section titled “(2)。/etc/nginx/conf.d/*.conf中的站点配置”
server {
server_name WEB.DOMAIN.com;
location / {
proxy_ssl_server_name on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass http://$host:$remote_port;
}
listen 443 ssl http2; # DO NOT NEED IF YOU USE NGINX
ssl_certificate path/to/certificate/fullchain.pem; # DO NOT NEED IF YOU USE NGINX
ssl_certificate_key path/to/certificate//privkey.pem; # DO NOT NEED IF YOU USE NGINX
}
sudo dnf install certbot

(2)。 (可选)安装 nginx 插件

Section titled “(2)。 (可选)安装 nginx 插件”
sudo dnf install python3-certbot-nginx

(3)。 (可选)安装 dns-cloudflare 插件

Section titled “(3)。 (可选)安装 dns-cloudflare 插件”
sudo dnf install python3-certbot-dns-cloudflare

(4)。申请SSL证书根据以上步骤,获得证书的方法有很多种。我们演示了两种匹配之前步骤(2)和(3)的方法。

Section titled “(4)。申请SSL证书根据以上步骤,获得证书的方法有很多种。我们演示了两种匹配之前步骤(2)和(3)的方法。”
  1. 使用 Nginx 签名
    sudo certbot --nginx -d domainname.com

这样,证书将自动配置在文件夹/etc/nginx/conf.d/中的 *.conf 中。 2. 使用 dns-cloudflare 签名 sudo certbot certonly --dns-cloudflare \ --dns-cloudflare-credentials \ ~/.secrets/certbot/cloudflare.ini \ -d example.com

这样就需要一个cloudflare密钥文件:cat cloudflare.ini # Cloudflare API credentials used by Certbot dns_cloudflare_api_token = 0123456789abcdef0123456789abcdef01234

sudo setsebool -P httpd_can_network_connect 1

[2]. https://certbot-dns-cloudflare.readthedocs.io/en/stable/

[3]. https://docs.nginx.com/

[4]. https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx

[5]. 让 Certbot 加密 [6]. SElinux-初探 [7]. RHEL9-激活 [8]. RHEL9-RPM-Fusion-Repo

在 RHEL/CentOS/Fedora 上安装 Samba[Samba] 是适用于 Linux 和 Unix 的标准 Windows 互操作程序套件,我们将在 RHEL/CentOS Linux 系统上配置它。


标签: - 桑巴舞类别: - Linux 日期:创建时间:2023-12-30# 更新时间:2024-01-19—

在 RHEL/CentOS/Fedora 上安装 Samba[Samba] 是适用于 Linux 和 Unix 的标准 Windows 互操作程序套件,我们将在 RHEL/CentOS Linux 系统上配置它。

Section titled “在 RHEL/CentOS/Fedora 上安装 Samba[Samba] 是适用于 Linux 和 Unix 的标准 Windows 互操作程序套件,我们将在 RHEL/CentOS Linux 系统上配置它。”

命令默认使用 root,对于其他用户,需要sudo。## 1.安装桑巴dnf install samba -y

对于 RHEL7.x 和 CentOS7.x 等较旧版本,请将dnf替换为yum。>

2. 添加用户useradd -s /sbin/nologin -d /PATH/TO/HOME/USERNAME> 添加用户USERNAME,主目录在/PATH/TO/HOME,无法登录。

Section titled “2. 添加用户useradd -s /sbin/nologin -d /PATH/TO/HOME/USERNAME> 添加用户USERNAME,主目录在/PATH/TO/HOME,无法登录。”

passwd USERNAME> 更改用户名的密码。

3、修改smb用户的访问密码smbpasswd -a USERNAME

Section titled “3、修改smb用户的访问密码smbpasswd -a USERNAME”

4.配置samba的配置文件更改文件/etc/samba/smb.conf。

Section titled “4.配置samba的配置文件更改文件/etc/samba/smb.conf。”
workgroup = SAMBA
security = user
log file = /var/log/samba/%m.log
log level = 1
min protocol = SMB3
passdb backend = tdbsam
hosts allow = 192.168.0.0/16
follow symlinks = yes
wide links = yes
unix extensions = no

将安全性设置为user> 将最低 samba 版本设置为SMB3>

[homes]
comment = Home Directories
valid users = %S, %D%w%S
create mask = 2640
directory mask = 2750
browseable = No
read only = No
inherit acls = Yes
inherit permissions = yes

作品1。分享其他目录在/etc/samba/smb.conf中添加新部分

Section titled “作品1。分享其他目录在/etc/samba/smb.conf中添加新部分”
[Data]
comment = Data
path = /PATH/TO/DATA
# valid users =
# write list =
valid users = USERNAME
create mask = 2660
directory mask = 2770
browseable = No
read only = No
inherit acls = Yes
inherit permissions = yes
# force user = GROUP
# force group = GROUP

如果该目录不在主目录下,则默认情况下由于 SELinux 而无法访问该目录。 设置布尔值来访问它: setsebool -P samba_export_all_rw 1

作品2。设置 SELinux 布尔值经过上述操作后,如果 SELinux 设置为diabled,则可以使用 samba 访问主目录,否则需要配置 SELinux。

Section titled “作品2。设置 SELinux 布尔值经过上述操作后,如果 SELinux 设置为diabled,则可以使用 samba 访问主目录,否则需要配置 SELinux。”

setsebool -P use_samba_home_dirs 1 setsebool -P samba_enable_home_dirs 1

作品3。设置防火墙如果您的系统中启用了firewalld,则必须将samba添加到firewall:

Section titled “作品3。设置防火墙如果您的系统中启用了firewalld,则必须将samba添加到firewall:”

firewall-cmd --add-server=samba --permanent然后重新加载防火墙:firewall-cmd --reload

5. 重新启动桑巴systemctl restart smbd

Section titled “5. 重新启动桑巴systemctl restart smbd”

[2]. https://linux.die.net/man/8/samba_selinux

[3]. Linux-防火墙-初探 [4]. SElinux-初探 [桑巴]:https://www.samba.org/

Linux 文本处理命令浅析

本文简单介绍Linux的三个文本处理命令->grep,ask,sed

grep [-abcEFGhHilLnqrsvVwxy][-A<显示列数>][-B<显示列数>][-C<显示列数>][-d<进行动作>][-e<范本样式>][-f<范本文件>][--help][范本样式][文件或目录...]

  • 参数:
-a 或 --text : 不要忽略二进制的数据。
-A<显示行数> 或 --after-context=<显示行数> : 除了显示符合范本样式的那一列之外,并显示该行之后的内容。
-b 或 --byte-offset : 在显示符合样式的那一行之前,标示出该行第一个字符的编号。
-B<显示行数> 或 --before-context=<显示行数> : 除了显示符合样式的那一行之外,并显示该行之前的内容。
-c 或 --count : 计算符合样式的列数。
-C<显示行数> 或 --context=<显示行数>或-<显示行数> : 除了显示符合样式的那一行之外,并显示该行之前后的内容。
-d <动作> 或 --directories=<动作> : 当指定要查找的是目录而非文件时,必须使用这项参数,否则grep指令将回报信息并停止动作。
-e<范本样式> 或 --regexp=<范本样式> : 指定字符串做为查找文件内容的样式。
-E 或 --extended-regexp : 将样式为延伸的正则表达式来使用。
-f<规则文件> 或 --file=<规则文件> : 指定规则文件,其内容含有一个或多个规则样式,让grep查找符合规则条件的文件内容,格式为每行一个规则样式。
-F 或 --fixed-regexp : 将样式视为固定字符串的列表。
-G 或 --basic-regexp : 将样式视为普通的表示法来使用。
-h 或 --no-filename : 在显示符合样式的那一行之前,不标示该行所属的文件名称。
-H 或 --with-filename : 在显示符合样式的那一行之前,表示该行所属的文件名称。
-i 或 --ignore-case : 忽略字符大小写的差别。
-l 或 --file-with-matches : 列出文件内容符合指定的样式的文件名称。
-L 或 --files-without-match : 列出文件内容不符合指定的样式的文件名称。
-n 或 --line-number : 在显示符合样式的那一行之前,标示出该行的列数编号。
-o 或 --only-matching : 只显示匹配PATTERN 部分。
-q 或 --quiet或--silent : 不显示任何信息。
-r 或 --recursive : 此参数的效果和指定"-d recurse"参数相同。
-s 或 --no-messages : 不显示错误信息。
-v 或 --invert-match : 显示不包含匹配文本的所有行。
-V 或 --version : 显示版本信息。
-w 或 --word-regexp : 只显示全字符合的列。
-x --line-regexp : 只显示全列符合的列。
-y : 此参数的效果和指定"-i"参数相同。
awk [选项参数] 'script' var=value file(s)
或
awk [选项参数] -f scriptfile var=value file(s)
  • 参数说明:
-F fs or --field-separator fs
指定输入文件折分隔符,fs是一个字符串或者是一个正则表达式,如-F:。
-v var=value or --asign var=value
赋值一个用户定义变量。
-f scripfile or --file scriptfile
从脚本文件中读取awk命令。
-mf nnn and -mr nnn
对nnn值设置内在限制,-mf选项限制分配给nnn的最大块数目;-mr选项限制记录的最大数目。这两个功能是Bell实验室版awk的扩展功能,在标准awk中不适用。
-W compact or --compat, -W traditional or --traditional
在兼容模式下运行awk。所以gawk的行为和标准的awk完全一样,所有的awk扩展都被忽略。
-W copyleft or --copyleft, -W copyright or --copyright
打印简短的版权信息。
-W help or --help, -W usage or --usage
打印全部awk选项和每个选项的简短说明。
-W lint or --lint
打印不能向传统unix平台移植的结构的警告。
-W lint-old or --lint-old
打印关于不能向传统unix平台移植的结构的警告。
-W posix
打开兼容模式。但有以下限制,不识别:/x、函数关键字、func、换码序列以及当fs是一个空格时,将新行作为一个域分隔符;操作符**和**=不能代替^和^=;fflush无效。
-W re-interval or --re-inerval
允许间隔正则表达式的使用,参考(grep中的Posix字符类),如括号表达式[[:alpha:]]。
-W source program-text or --source program-text
使用program-text作为源代码,可与-f命令混用。
-W version or --version
打印bug报告信息的版本。

sed [-hnV][-e<script>][-f<script文件>][文本文件]

  • 参数说明:
-e<script>或--expression=<script> 以选项中指定的script来处理输入的文本文件。
-f<script文件>或--file=<script文件> 以选项中指定的script文件来处理输入的文本文件。
-h或--help 显示帮助。
-n或--quiet或--silent 仅显示script处理后的结果。
-V或--version 显示版本信息。
  • 动作说明:
a :新增, a 的后面可以接字串,而这些字串会在新的一行出现(目前的下一行)~
c :取代, c 的后面可以接字串,这些字串可以取代 n1,n2 之间的行!
d :删除,因为是删除啊,所以 d 后面通常不接任何咚咚;
i :插入, i 的后面可以接字串,而这些字串会在新的一行出现(目前的上一行);
p :打印,亦即将某个选择的数据印出。通常 p 会与参数 sed -n 一起运行~
s :取代,可以直接进行取代的工作哩!通常这个 s 的动作可以搭配正规表示法!例如 1,20s/old/new/g 就是啦!

例:

sed 's/\"//g;s/,//g;'

[1].https://www.runoob.com/linux/linux-command-manual.html

[2]. Shell字符串截取

[3]. Cloudflare-DDNS-with-ShellScripts

[4]. Set-Raspberry-as-WiFi-Router