Unix & Linux

Linux,FreeBSD和其他类似Un * x的操作系统用户的问答

3
sed输出如何像printf的格式化打印一样格式化?
sed可以用类似于printf的格式化打印格式的字符串替换文本吗? 以下sed命令用变量中指定的多个值替换以“ $ domain”的当前值开头的行。 /bin/sed "s/\(^${domain} *${limittype} * ${limititem}.*\)/$EXPL#\1\n${domain} ${limittype} ${limititem} ${value}/" /etc/security/limits.conf 但是,由于domain等的值的长度不同,因此无法正确对齐输出。 因此输出将类似于 #oracle hard nproc 131072 oracle hard nproc 666 虽然有效,但很难阅读。我宁愿得到像 #oracle hard nproc 131072 oracle hard nproc 666 我可以拿到的最好的输出是: /bin/sed "s/\(^${domain}\)\( *\)\(${limittype}\)\( *\)\(${limititem}\)\( *\)\(.*\)/$EXPL#\1\2\3\4\5\6\7\n${domain}\2${limittype}\4${limititem}\6${value}/" /etc/security/limits.conf 但是我相信必须有一种更优雅的方法来做到这一点。 所述sed的一个衬里文件包含一些实例中使用指定数目的字符,例如 sed -e :a -e 's/^.\{1,78\}$/ &/;ta' # set at …

4
字母的ASCII艺术,字母使用自己的字符
如果我执行 banner ABC 我得到: # ###### ##### # # # # # # # # # # # # # ###### # ####### # # # # # # # # # # # ###### ##### 另一个程序figlet拥有更精致的字体和用于连接相邻字符的机制,例如: _ ____ ____ / \ | __ ) / ___| / _ \ …

1
for循环在bash中不起作用
我有下面的代码来替换多个文件中的某些strigns,但是for循环正在检查第一个文件,而不执行perl脚本。下面是我的代码 if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ] then for file in $(./zebu.work.post_opt/ZEBU_CTO_FT_MOD*); do perl -i -p -e 's/input/inout/g' $file; perl -i -p -e 's/output/inout/g' $file; perl -i -p -e 's/wire.*\n/tran\(i0,\ o\);/g' $file; perl -i -p -e 's/assign.*\n//g' $file; done fi
7 bash  for 

1
[[expr1 ||之间的差异 expr2]]和[[expr1]] || [[expr2]]
考虑两个条件表达式expr1和expr2,例如$i -eq $j和$k -eq $l。我们可以用bash多种方式编写。这有两种可能性 [[ expr1 || expr2 ]] [[ expr1 ]] || [[ expr2 ]] 我相当确定我在这里看到了推荐使用第二种方法的建议,但是我找不到证据来支持这一点。 这是一个示例脚本,似乎证明没有区别: for i in 0 1 do for j in 0 1 do for k in 0 1 do for l in 0 1 do if [[ $i -eq $j || $k …
7 bash 

4
是否有与发行版无关的配置管理软件?
我不想将自己标记为特定的配置管理器模块,例如Ansible的apt模块或yum模块。 是否有与发行版无关的配置管理软件,或者至少有一个具有发行版不可知代码的软件来为Arch Linux安装以下软件包? 我问这个问题是因为找不到适合在Arch Linux上安装LAMP的Ansible星系角色,并且以下Debian的Bash脚本不适用于Arch: #!/bin/bash apt update -y apt upgrade ufw sshguard unattended-upgrades wget curl git zip unzip tree -y ufw --force enable ufw allow 22,25,80,443 apt upgrade lamp-server^ ssmtp -y apt upgrade python-certbot-apache -y apt upgrade php-{cli,curl,mbstring,mcrypt,gd} phpmyadmin -y


1
Fedora 29:无法为回购“ fedora-modular”同步缓存
我将Fedora 27升级到28,使用了它(没有运行dnf更新),然后又升级到了29。今天早上,我尝试了 sudo dnf -v update 我得到了 sudo dnf -v更新 加载的插件:builddep,config-manager,copr,debug,debuginfo-install,下载,generate_completion_cache,需要重启,游乐场,重新封闭,repodiff,repograph,repomanage,reposync,系统升级 DNF版本:4.0.9 cachedir:/ var / cache / dnf 未知的配置值:/etc/yum.repos.d/fedora-cisco-openh264.repo中的failovermethod = priority;配置:ID为“ failovermethod”的OptionBinding不存在 未知的配置值:/etc/yum.repos.d/fedora-modular.repo中的failovermethod = priority;配置:ID为“ failovermethod”的OptionBinding不存在 ... 回购:从远程下载:fedora-modular 错误:Curl错误(60):对等证书无法使用https://mirrors.fedoraproject.org/metalink?repo=fedora-modular-29&arch=x86_64的给定CA证书进行身份验证[SSL证书问题:证书链中的自签名证书](https://mirrors.fedoraproject.org/metalink?repo=fedora-modular-29&arch=x86_64)。 Fedora模块化29-x86_64 0.0 B / s | 0 B 00:01 无法下载'https://mirrors.fedoraproject.org/metalink?repo=fedora-modular-29&arch=x86_64':无法准备内部镜像列表:卷曲错误(60):对等证书无法使用https:/的给定CA证书进行身份验证/mirrors.fedoraproject.org/metalink?repo=fedora-modular-29&arch=x86_64 [SSL证书问题:证书链中的自签名证书]。 错误:无法为回购“ fedora-modular”同步缓存 真正的问题看起来像 [SSL certificate problem: self signed certificate in …



3
什么是`。/ path / command`可以吗?(点后的空格,绝对路径)
从本Bash完成指南中,我们了解到,要使Bash执行自动补全,必须执行一项操作. /etc/etc/bash_completion.d/foobar(注意后面的空格.),Bash才能完成工作。 $ /etc/bash_completion.d/ssh bash: /etc/bash_completion.d/ssh: Permission denied $ . /etc/bash_completion.d/ssh $ ls -l /etc/bash_completion.d | grep ssh -rw-r--r-- 1 root root 297 Jan 28 18:04 ssh .该source命令是快捷方式吗?如果没有,那是什么?这是不可能的谷歌,man source回报什么,apropos source并info source给这么多不相关的信息,我不能告诉我们,如果有什么我要找的是在那里。我怎么可能甚至开始使用RTFM自己找到该问题的答案?
7 bash 

1
有没有办法查看在TCP端口上侦听的进程是否收到消息?
根据tcpdump,我的服务器收到以下TCP数据包: 12:52:29.603233 00:19:e2:9e:df:f0 00:16:3e:6a:25:3f, ethertype IPv4 (0x0800), length 74: 10.10.10.65.38869 192.168.215.82.22: Flags [S], seq 567054335, win 5840, options [mss 1460,sackOK,TS val 2096335479 ecr 0,nop,wscale 0], length 0 如上所示,这是到TCP端口22的TCP SYN数据包,在我的情况下,该数据包侦听a sshd。我想看看这个TCP数据包是否到达sshd进程。我猜一个选择是sshd在调试模式下重启。但是,是否还有其他聪明的工具/方法可以查看在TCP端口上侦听的进程是否收到消息?如果是TCP SYN数据包,我想这是内核TCP / IP堆栈,它将发送TCP SYN + ACK,而不是sshd?

1
GNOME密钥管理器和gnupg
我明白了 gpg: WARNING: The GNOME keyring manager hijacked the GnuPG agent. gpg: WARNING: GnuPG will not work proberly - please configure that tool to not interfere with the GnuPG system! 当我将gnupg-agent与mutt一起使用时。但是该警告并没有为我提供解决问题的线索,也无法从GNOME文档中找到信息。
7 gnome  gnome3  pgp 

3
如何从bcache中删除缓存设备?
我相信,一旦确定我的缓存设备状态为“干净”: $ sudo cat /sys/block/bcache0/bcache/state 我可以将其关闭后再从计算机上物理移除,或者使用liveCD进行引导,并使用以下方法清洁超级块: $ sudo dd if=/dev/zero of=<backing device for cache> bs=1024 count=1024 但是我在任何地方都找不到确认,这个过程不会弄乱任何东西。
7 linux  memory  bcache 

2
如何对宽度最小的项目列表进行分栏?
我该如何将未分类的输入分成列ls? ls 正在创建每行最小宽度的优化表,例如: ls 2 dsao file with space with 5 e g wsdl-rubo-6cb0f1a9086e80c d file leading space 但是,如果我将输出输入column(例如,一行中的每个文件),它会将每一行填充相同的宽度,因此适合屏幕宽度: for i in *; do echo "$i"; done | column 2 file with space 5 g d leading space dsao with e wsdl-rubo-6cb0f1a9086e80c file (我在这里仅使用文件列表来生成与示例相同的输出,我正在寻找这样一种解决方案来最终对其他内容进行列化。) 如何对col-width可变的任何输出进行整理?
7 bash  ls 

2
在Linux中使用print命令代替echo
我只是可以使用linux echo命令在终端中打印一条消息。 prayag@prayag$ echo "prayag works on JVM" prayag works on JVM 我可以使用print命令获得相同的输出。 我实际上浏览了他们的手册,在其中$ man print将其描述为Run-mailcap-programs,这是我以前从未听说过的术语。并且了解到它是用于基于MIME查找用于打开文件的正确程序的。 那么,有没有办法单独使用而不是打印简单的线条?printecho 在Need需要在bash脚本中将文本文件的内容分配给变量时发现了类似的问题,但有人echo在print那儿提出建议。 我尝试跟随,但遇到了问题。 $ print --"text/plain" "prayag works on JVM" Warning: unknown mime-type for "prayag works on JVM" -- using "application/octet-stream" Error: no such file "prayag works on JVM" 它要求提供包含文件的文件。 $ print --"text/plain" application.properties …
7 shell  command  echo 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.