【原创】调用有道翻译Api翻译Linux命令accessdb输出内容 - Go语言中文社区

【原创】调用有道翻译Api翻译Linux命令accessdb输出内容


accessdb输出内容

在linux控制台输入accessdb指令,结果密密麻麻地输出了一大堆。

[root@status ~]# accessdb
$version$ -> "2.5.0"
. -> "- 1 1 1633086380 0 B - - gz bash built-in commands, see bash(1)"
.k5identity -> "- 5 5 1629954739 0 B - - gz Kerberos V5 client principal selection rules"
.k5login -> "- 5 5 1629954739 0 B - - gz Kerberos V5 acl file for host access"
.ldaprc -> "- 5 5 1628572339 0 C ldap.conf - gz "
/etc/anacrontab -> "- 5 5 1573231664 0 C anacrontab - gz "
30-systemd-environment-d-generator -> "- 8 8 1633446453 0 B - - gz Load variables specified by environment.d"
: -> "- 1 1 1633086380 0 B - - gz bash built-in commands, see bash(1)"
GnuPG~7 -> "- 7 7 1589573252 0 C gnupg2 - gz "
PAM~8 -> "- 8 8 1620364026 0 A - - gz Pluggable Authentication Modules for Linux"
RAND~7ssl -> "- 7ssl 7 1626866126 0 A - - gz the OpenSSL random generator"
RDMA-NDD~8 -> "- 8 8 1621264375 0 C rdma-ndd - gz "
SELinux~8 -> "- 8 8 1603743632 0 C selinux - gz "
TuneD~8 -> "- 8 8 1626892915 0 C tuned - gz "

查看accessdb的帮助,结果帮助内容只有一点点(一页)。大概的意思是说,这个指令以人类可读的格式转储man db数据库的内容。

[root@status ~]# man accessdb
ACCESSDB(8)                     Manual pager utils                    ACCESSDB(8)

NAME
       accessdb - dumps the content of a man-db database in a human readable for‐
       mat

SYNOPSIS
       /usr/sbin/accessdb [-d?V] [<index-file>]

DESCRIPTION
       accessdb will output the data contained within  a  man-db  database  in  a
       human   readable   form.    By   default,  it  will  dump  the  data  from
       /var/cache/man/index.<db-type>, where <db-type> is dependent on the  data‐
       base library in use.

       Supplying an argument to accessdb will override this default.

OPTIONS
       -d, --debug
              Print debugging information.

       -?, --help
              Print a help message and exit.

       --usage
              Print a short usage message and exit.

       -V, --version
              Display version information.

AUTHOR
       Wilf. (G.Wilford@ee.surrey.ac.uk).
       Fabrizio Polacco (fpolacco@debian.org).
       Colin Watson (cjwatson@debian.org).

差不多就是系统中每个命令的简单说明。看来比较实用。但是描述的内容是用英文写的,对于母语非英文的我来说,读起来太慢。那么,我们就调用翻译的API,将其顺便翻译成中文来阅读吧。由于机器翻译不太准确,那么我们就来个中英文对照吧。

申请翻译的API

这里,我们使用有道翻译API。

首先,百度搜索“有道翻译API”,找到“http://fanyi.youdao.com/openapi”,打开链接。

有账号的话,登录系统。没账号的话,申请一个再登录系统。

跳转到 https://ai.youdao.com/console/#/service-singleton/text-translation文本翻译。如果没有应用的话,创建一个应用。首次使用它,系统会送100元的时长,有效期1年。

右侧中部,各种代码编写的示例代码,这里我们选择C#,抄下来,修改这三个参数就可以用了。
appKey,appSecret ,来自于创建的应用。

			string q = "待输入的文字";
            string appKey = "您的应用ID";
            string appSecret = "您的应用密钥"

代码我修改了一下,将其封装成一个类,可以供接下来调用。

    public class YouDaoFanyiV3
    {
        public YouDaoFanyiResult Trans(string query)
        {
            Dictionary<String, String> dic = new Dictionary<String, String>();
            string url = "https://openapi.youdao.com/api";
            string appKey = "14b33f4513380000000";
            string appSecret = "xfACgC1jAAUx9T9n00000000";
            string salt = DateTime.Now.Millisecond.ToString();
            //dic.Add("from", "源语言");
            //dic.Add("to", "目标语言");
            dic.Add("signType", "v3");
            TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
            long millis = (long)ts.TotalMilliseconds;
            string curtime = Convert.ToString(millis / 1000);
            dic.Add("curtime", curtime);
            string signStr = appKey + Truncate(query) + salt + curtime + appSecret; ;
#pragma warning disable SYSLIB0021 // 类型或成员已过时
            string sign = ComputeHash(signStr, new SHA256CryptoServiceProvider());
#pragma warning restore SYSLIB0021 // 类型或成员已过时
            dic.Add("q", System.Web.HttpUtility.UrlEncode(query));
            dic.Add("appKey", appKey);
            dic.Add("salt", salt);
            dic.Add("sign", sign);
            //dic.Add("vocabId", "您的用户词表ID");
            var result = Post(url, dic);
            return JsonSerializer.Deserialize<YouDaoFanyiResult>(result);

        }
        private string ComputeHash(string input, HashAlgorithm algorithm)
        {
            Byte[] inputBytes = Encoding.UTF8.GetBytes(input);
            Byte[] hashedBytes = algorithm.ComputeHash(inputBytes);
            return BitConverter.ToString(hashedBytes).Replace("-", "");
        }

        private string Post(string url, Dictionary<String, String> dic)
        {
            string result = "";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            StringBuilder builder = new StringBuilder();
            int i = 0;
            foreach (var item in dic)
            {
                if (i > 0)
                    builder.Append("&");
                builder.AppendFormat("{0}={1}", item.Key, item.Value);
                i++;
            }
            byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
            req.ContentLength = data.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);
                reqStream.Close();
            }
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            Stream stream = resp.GetResponseStream();
            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }
            return result;
        }

        private string Truncate(string q)
        {
            if (q == null)
            {
                return null;
            }
            int len = q.Length;
            return len <= 20 ? q : (q.Substring(0, 10) + len + q.Substring(len - 10, 10));
        }
    }

保存accessdb输出内容

先浏览一下,这个命令输出的man db中命令的个数。1872个命令帮助。

[root@status ~]# accessdb |wc -l
1872

将accessdb输出内容保存到一个文本文件,顺排序一下

[root@status ~]# accessdb | sort > accessdb.txt
[root@status ~]# ll
total 180
-rw-r--r--. 1 root root 155218 Apr 10 20:48 accessdb.txt
-rw-------. 1 root root   1068 Oct 15 18:41 anaconda-ks.cfg
[root@status ~]#

将生成的accessdb.txt文件下载到windows pc机。
打开Visual Studio 2022,创建一个控制台项目,添加上面修改后的类,在Program.cs文件中添加如下代码:

using ConsoleApp10;
using System.Text;

var output = new StringBuilder();
YouDaoFanyiV3 youDaoFanyiV3 = new YouDaoFanyiV3();

var data = File.ReadAllLines("E:\\accessdb.txt").ToList();
data.Sort(StringComparer.Ordinal);

char firstChar = 'z';
foreach (var item in data)
{
    if (firstChar != item[0])
    {
        firstChar = item[0];
        output.AppendLine("```");
        output.AppendLine("## 以" + firstChar + "开头的命令");
        output.AppendLine("```bash");
    }
    var lines = item.Split("->");
    var command = lines[0].Trim();
    output.AppendLine(command);

    var descript = "";
    try
    {
        descript = lines[1].Trim().Split("gz")[1].Trim().Trim('\"').Trim();
    }
    catch
    {
        descript = lines[1].Trim().Trim('\"').Trim(); 
    }
    if (descript == "")
    {
        output.AppendLine();
        continue;
    }

    output.Append("\t");
    output.AppendLine(descript.Replace("'","’"));
    output.Append("\t");

    Console.WriteLine(command);

    var trans = youDaoFanyiV3.Trans(descript);
    output.AppendLine(trans.translation[0]);

    Console.WriteLine("\t" + trans.translation[0]);
}

output.AppendLine("```");
File.WriteAllText("E:\\accessdb_ok.txt", output.ToString());

编译运行,执行完毕后,得到accessdb_ok.txt文件。文件内容如下:

翻译后的accessdb输出内容

以$开头的命令

$version$
	2.5.0
	2.5.0

以.开头的命令

.
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
.k5identity
	Kerberos V5 client principal selection rules
	Kerberos V5客户机主体选择规则
.k5login
	Kerberos V5 acl file for host access
	用于主机访问的Kerberos V5 acl文件
.ldaprc

以/开头的命令

/etc/anacrontab

以3开头的命令

30-systemd-environment-d-generator
	Load variables specified by environment.d
	由environment.d指定的加载变量

以:开头的命令

:
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)

以G开头的命令

GnuPG~7

以P开头的命令

PAM~8
	Pluggable Authentication Modules for Linux
	Linux可插拔认证模块

以R开头的命令

RAND~7ssl
	the OpenSSL random generator
	OpenSSL随机生成器
RDMA-NDD~8

以S开头的命令

SELinux~8

以T开头的命令

TuneD~8

以[开头的命令

[
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)

以a开头的命令

access.conf
	the login access control table file
	登录访问控制表文件
accessdb
	dumps the content of a man-db database in a human readable format
	以人类可读的格式转储man-db数据库的内容
acl
	Access Control Lists
	访问控制列表
addgnupghome
	Create .gnupg home directories
	创建.gnupg主目录
addpart
	tell the kernel about the existence of a partition
	告诉内核分区的存在
adduser
	create a new user or update default new user information
	创建新用户或更新默认新用户信息
agetty
	alternative Linux getty
	选择Linux盖蒂
alias
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
alternatives
	maintain symbolic links determining default commands
	维护确定默认命令的符号链接
anacron
	runs commands periodically
	定期运行命令
anacrontab
	configuration file for Anacron
	Anacron配置文件
applygnupgdefaults
	Run gpgconf - apply-defaults for all users.
	对所有用户执行gpgconf - apply-defaults命令。
apropos
	search the manual page names and descriptions
	搜索手册页面名称和描述
arch
	print machine hardware name (same as uname -m)
	打印机器硬件名称(与uname -m相同)
arpd
	userspace arp daemon.
	用户空间arp守护进程。
arping
	send ARP REQUEST to a neighbour host
	向邻居主机发送ARP请求
asn1parse
	ASN.1 parsing tool
	asn . 1解析工具
audit-plugins

audit.rules
	a set of rules loaded in the kernel audit system
	加载在内核审计系统中的一组规则
audit2allow
	generate SELinux policy allow/dontaudit rules from logs of denied operations
	从被拒绝的操作日志中生成SELinux policy allow/dontaudit规则
audit2why
	generate SELinux policy allow/dontaudit rules from logs of denied operations
	从被拒绝的操作日志中生成SELinux policy allow/dontaudit规则
auditctl
	a utility to assist controlling the kernel’s audit system
	一个帮助控制内核审计系统的工具
auditd
	The Linux Audit daemon
	Linux Audit守护进程
auditd-plugins
	realtime event receivers
	实时事件接收者
auditd.conf
	audit daemon configuration file
	审计守护进程配置文件
augenrules
	a script that merges component audit rule files
	合并组件审计规则文件的脚本
aulast
	a program similar to last
	类似于最后的程序
aulastlog
	a program similar to lastlog
	类似于lastlog的程序
aureport
	a tool that produces summary reports of audit daemon logs
	生成审计守护进程日志摘要报告的工具
ausearch
	a tool to query audit daemon logs
	用于查询审计守护进程日志的工具
ausearch-expression
	audit search expression format
	审计搜索表达式格式
ausyscall
	a program that allows mapping syscall names and numbers
	一个允许映射系统调用名和号码的程序
authselect
	select system identity and authentication sources.
	选择系统标识和认证源。
authselect-migration
	A guide how to migrate from authconfig to authselect.
	如何从authconfig迁移到authselect的指南。
authselect-profiles
	how to extend authselect profiles.
	如何扩展authselect配置文件。
autrace
	a program similar to strace
	类似于strace的程序
auvirt
	a program that shows data related to virtual machines
	显示与虚拟机有关的数据的程序
avcstat
	Display SELinux AVC statistics
	显示SELinux AVC统计信息
awk
	pattern scanning and processing language
	模式扫描和处理语言

以b开头的命令

b2sum
	compute and check BLAKE2 message digest
	计算并检查BLAKE2消息摘要
badblocks
	search a device for bad blocks
	在设备中查找坏块
base32
	base32 encode/decode data and print to standard output
	Base32编码/解码数据并打印到标准输出
base64
	base64 encode/decode data and print to standard output
	Base64编码/解码数据并打印到标准输出
basename
	strip directory and suffix from filenames
	从文件名中去掉目录和后缀
bash
	GNU Bourne-Again SHell
	GNU Bourne-Again壳
bashbug
	report a bug in bash
	在bash中报告bug
bashbug-64
	report a bug in bash
	在bash中报告bug
bg
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
bind
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
binfmt.d
	Configure additional binary formats for executables at boot
	在引导时为可执行文件配置额外的二进制格式
bio
	Basic I/O abstraction
	基本的I / O的抽象
biosdecode
	BIOS information decoder
	BIOS信息译码器
biosdevname
	give BIOS-given name of a device
	give bios指定的设备名称
blkdeactivate
	utility to deactivate block devices
	实用程序去激活块设备
blkdiscard
	discard sectors on a device
	丢弃设备上的扇区
blkid
	locate/print block device attributes
	定位/打印块设备属性
blkzone
	run zone command on a device
	在设备上执行zone命令
blockdev
	call block device ioctls from the command line
	从命令行调用块设备ioctls
bond2team
	Converts bonding configuration to team
	将绑定配置转换为团队
booleans
	booleans 5 booleans 8
	布尔值5,布尔值8
booleans~5
	The SELinux booleans configuration files
	SELinux布尔值配置文件
booleans~8
	Policy booleans enable runtime customization of SELinux policy
	策略布尔值启用SELinux策略的运行时自定义
bootctl
	Control the firmware and boot manager settings
	控制固件和启动管理器设置
bootup
	System bootup process
	系统启动过程
break
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
bridge
	show / manipulate bridge addresses and devices
	显示/操作网桥地址和设备
builtin
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
builtins
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
busctl
	Introspect the bus
	反思公共汽车
bwrap
	container setup utility
	容器设置实用程序

以c开头的命令

c_rehash

ca
	sample minimal CA application
	样本最小CA应用
ca-legacy
	Manage the system configuration for legacy CA certificates
	管理旧CA证书的系统配置
cache_check
	validates cache metadata on a device or file.
	验证设备或文件上的缓存元数据。
cache_dump
	dump cache metadata from device or file to standard output.
	将缓存元数据从设备或文件转储到标准输出。
cache_metadata_size
	Estimate the size of the metadata device needed for a given configuration.
	估计给定配置所需的元数据设备的大小。
cache_repair
	repair cache binary metadata from device/file to device/file.
	修复设备/文件到设备/文件的缓存二进制元数据。
cache_restore
	restore cache metadata file to device or file.
	将缓存元数据文件恢复到设备或文件。
cache_writeback
	writeback dirty blocks to the origin device.
	回写脏块到原始设备。
cal
	display a calendar
	显示一个日历
caller
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
capsh
	capability shell wrapper
	能力壳包装
captoinfo
	convert a termcap description into a terminfo description
	将一个termcap描述转换为一个terminfo描述
cat
	concatenate files and print on the standard output
	连接文件并在标准输出上打印
catman
	create or update the pre-formatted manual pages
	创建或更新预格式化的手册页
cd
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
cert8.db
	Legacy NSS certificate database
	遗留的NSS证书数据库
cert9.db
	NSS certificate database
	NSS证书数据库
cfdisk
	display or manipulate a disk partition table
	显示或操作磁盘分区表
cgdisk
	Curses-based GUID partition table (GPT) manipulator
	基于诅咒的GUID分区表(GPT)操纵符
chacl
	change the access control list of a file or directory
	修改文件或目录的访问控制列表
chage
	change user password expiry information
	修改用户密码过期信息
chattr
	change file attributes on a Linux file system
	在Linux文件系统上修改文件属性
chcat
	change file SELinux security category
	更改文件SELinux安全类别
chcon
	change file SELinux security context
	更改文件SELinux安全上下文
chcpu
	configure CPUs
	cpu配置
checkmodule
	SELinux policy module compiler
	SELinux策略模块编译器
checkpolicy
	SELinux policy compiler
	SELinux策略编译器
chgpasswd
	update group passwords in batch mode
	批量更新组密码
chgrp
	change group ownership
	改变组所有权
chkconfig
	updates and queries runlevel information for system services
	更新和查询系统服务的运行级别信息
chmem
	configure memory
	配置内存
chmod
	change file mode bits
	改变文件模式位
chown
	change file owner and group
	更改文件所有者和组
chpasswd
	update passwords in batch mode
	批量更新密码
chroot
	run command or interactive shell with special root directory
	在特殊的根目录下运行命令或交互式shell
chrt
	manipulate the real-time attributes of a process
	操作流程的实时属性
chvt
	change foreground virtual terminal
	改变前台虚拟终端
ciphers
	SSL cipher display and cipher list tool
	SSL密码显示和密码列表工具
cksum
	checksum and count the bytes in a file
	校验和计算文件中的字节数
clear
	clear the terminal screen
	清除终端屏幕
clock
	time clocks utility
	时钟时间效用
clockdiff
	measure clock difference between hosts
	测量主机之间的时钟差异
cmp
	compare two files byte by byte
	逐字节比较两个文件
cms
	CMS utility
	CMS工具
col
	filter reverse line feeds from input
	从输入中过滤反馈线
colcrt
	filter nroff output for CRT previewing
	滤镜nroff输出用于CRT预览
colrm
	remove columns from a file
	从文件中删除列
column
	columnate lists
	columnate列表
comm
	compare two sorted files line by line
	逐行比较两个已排序的文件
command
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
compgen
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
complete
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
compopt
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
config
	config 5ssl config 5
	配置5ssl配置5 .单击“确定”
config-util
	Common PAM configuration file for configuration utilities
	用于配置实用程序的公共PAM配置文件
config~5

config~5ssl
	OpenSSL CONF library configuration files
	OpenSSL CONF库配置文件
console.apps
	specify console-accessible privileged applications
	指定控制台可访问的特权应用程序
console.handlers
	file specifying handlers of console lock and unlock events
	指定控制台锁定和解锁事件处理程序的文件
console.perms
	permissions control file for users at the system console
	在系统控制台为用户提供权限控制文件
consoletype
	print type of the console connected to standard input
	控制台连接到标准输入的打印类型
continue
	bash built-in commands, see bash(1)
	Bash内置命令,参见Bash (1)
coredump.conf
	Core dump storage configuration files
	核心转储存储配置文件
coredump.conf.d
	Core dump storage configuration files
	核心转储存储配置文件
coredumpctl
	Retrieve and process saved core dumps and metadata
	检索和处理保存的核心转储文件和元数据
cp
	copy files and directories
	复制文件和目录
cpio
	cpio 5 cpio 1
	cpio 5 cpio 1
cpio~1
	copy files to and from archives
	将文件复制到存档中或从存档中复制
cpio~5
	format of cpio archive files
	cpio归档文件的格式
cpupower
	Shows and sets processor power related values
	显示和设置处理器功率相关值
cpupower-frequency-info
	Utility to retrieve cpufreq kernel information
	检索cpufreq内核信息的实用程序
cpupower-frequency-set
	A small tool which allows to modify cpufreq settings.
	一个允许修改cpufreq设置的小工具。
cpupower-idle-info
	Utility to retrieve cpu idle kernel information
	检索cpu空闲内核信息的实用程序
cpupower-idle-set
	Utility to set cpu idle state specific kernel options
	实用程序设置cpu空闲状态特定的内核选项
cpupower-info
	Shows processor power related kernel or hardware configurations
	显示与处理器功率相关的内核或硬件配置
cpupower-monitor
	Report processor frequency and idle statistics
	报告处理器频率和空闲统计信息
cpupower-set
	Set processor power related kernel or hardware configurations
	设置与处理器功率相关的内核或硬件配置
cracklib-check
	Check passwords using libcrack2
	使用libcrack2检查密码
cracklib-format
	cracklib dictionary utilities
	cracklib词典工具
cracklib-packer
	cracklib dictionary utilities
	cracklib词典工具
cracklib-unpacker
	cracklib dictionary utilities
	cracklib词典工具
create-cracklib-dict
	Check passwords using libcrack2
	使用libcrack2检查密码
crl
	CRL utility
	CRL效用
crl2pkcs7
	Create a PKCS#7 structure from a CRL and certificates
	从CRL和证书创建PKCS#7结构
cron
	daemon to execute scheduled commands
	执行预定命令的守护进程
crond
	daemon to execute scheduled commands
	执行预定命令的守护进程
cronnext
	time of next job cron will execute
	下一个任务cron执行的时间
crontab
	crontab 5 crontab 1
	Crontab 5
crontabs
	configuration and scripts for running periodical jobs
	用于运行定期作业的配置和脚本
crontab~1
	maintains crontab files for individual users
	为个别用户维护crontab文件
crontab~5
	files used to schedule the execution of programs
	用来安排程序执行的文件
crypt
	storage format 
                            
                            版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/u013667796/article/details/124084862
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2023-01-03 14:41:37
  • 阅读 ( 313 )
  • 分类:Linux

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢