Unix & Linux

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

7
Bash awk命令带引号
我一直在努力寻找这个问题的答案。我正在编写一个快速脚本,以基于awk的输出运行命令。 ID_minimum=1000 for f in /etc/passwd; do awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" { print "xfs_quota -x -c 'limit bsoft=5g bhard=6g $1' /home "}' $f; done 问题在于,该-c参数使用单引号引起来的命令,我无法弄清楚如何正确地对其进行转义,并且也$1无法扩展为用户名。 本质上,我只是想将其输出: xfs_quota -x -c 'limit bsoft=5g bhard=6g userone' /home xfs_quota -x -c 'limit bsoft=5g bhard=6g usertwo' /home 等等...
8 bash  shell  scripting 

2
仅在数据覆盖时覆盖文件
我试图用命令输出覆盖文件,但前提是有任何输出。也就是说,我通常要 mycommand > myfile 但是,如果这将myfile用空数据覆盖,我希望保留的旧版本myfile。我认为ifne应该可以使用一些东西 mycommand | ifne (cat > myfile) 但这不起作用... 间接方法 mycommand | tee mytempfile | ifne mv mytempfile myfile 可以,但是我认为使用该临时文件是不合理的。 问:为什么我的第一个想法无效?可以工作吗?还是为我的原始问题提供了另一个不错的,也许是完全不同的解决方案?
8 bash 

7
在冒号之前获取内容
我在Linux上有一个文本文件,其内容如下: help.helloworld.com:latest.world.com dev.helloworld.com:latest.world.com 我想在冒号之前获取内容,如下所示: help.helloworld.com dev.helloworld.com 我该如何在终端机中做到这一点?




4
如何在一天的特定时间显示倒数计时器?
我是老师。我的课程中有某些例程,在Orage中通过定时事件宣布,并发送到通知中。例如: 清理 放椅子 我的学生要求我在屏幕上放置一个倒计时时钟,以警告事件发生还剩下多少时间。我使用XFce,因此它既可以显示在屏幕顶部的面板上,也不会被全屏项目覆盖,或者可以显示为始终不可显示的透明抬头显示,该显示始终显示在每个窗口的上方。 例如: 3:10直到清理。 6:10直到上完课。 这些不是手动激活的倒数计时,而是在每天的特定时间发生,例如10分钟的倒计时从3:00 pm开始,到3:10 pm结束为零。我可以orage用来激活脚本,但是需要某种方式来显示计数器和信息。 有什么办法在屏幕上显示这样的倒数计时器吗?


5
为什么不对由$()中的命令打印的{1,2}进行插值?
我所在的目录中有两个文本文件: $ touch test1.txt $ touch test2.txt 当我尝试使用某种模式列出文件(使用Bash)时,它可以工作: $ ls test?.txt test1.txt test2.txt $ ls test{1,2}.txt test1.txt test2.txt 但是,当使用内含的命令生成模式时$(),只有一种模式有效: $ ls $(echo 'test?.txt') test1.txt test2.txt $ ls $(echo 'test{1,2}.txt') ls: cannot access test{1,2}.txt: No such file or directory 这里发生了什么?为什么该模式{1,2}不起作用?

6
仅查找那些包含与该文件夹同名的文件的文件夹
我想找到所有包含具有相同名称(和扩展名.md)的markdown文件的子文件夹。 例如:我要查找以下子文件夹: Apple/Banana/Orange #Apple/Banana/Orange/Orange.md exists Apple/Banana #Apple/Banana/Banana.md exists Apple/Banana/Papaya #Apple/Banana/Papaya/Papaya.md exists 注意:目录中可以有其他文件或子目录。 有什么建议么? 可以使用以下代码测试问题的解决方案: #!/usr/bin/env bash # - goal: "Test" # - author: Nikhil Agarwal # - date: Wednesday, August 07, 2019 # - status: P T' (P: Prototyping, T: Tested) # - usage: ./Test.sh # - include: # 1. …

2
百胜检查更新失败
从今天早上开始,我在使用yumCentos 7.6 进行软件包更新检查时出错。当我跑步时: $ sudo yum clean all && sudo yum check-update Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Cleaning repos: base epel extras google-cloud-compute google-cloud-sdk updates Cleaning up list of fastest mirrors Other repos take …
8 centos  yum 


2
setuid位为何工作不一致?
我写了代码: // a.c #include <stdlib.h> int main () { system("/bin/sh"); return 0; } 用命令编译: gcc a.c -o a.out 在其上添加setuid位: sudo chown root.root a.out sudo chmod 4755 a.out 在Ubuntu 14.04上,当我以普通用户身份运行时,我获得了root特权。 但是在Ubuntu 16.04上,我仍然拥有当前用户的shell。 为什么不同?

3
回显tail命令会产生意外的输出?
此命令单独运行时,将产生预期的结果(crontab的最后一行): tail -n 1 /etc/crontab 但是,当我将其作为echo命令的一部分运行以将结果发送到文件时,它会添加工作目录中所有文件的摘要以及预期结果: sudo bash -c 'echo $(tail -n 1 /etc/crontab) > /path/to/file' 为什么此命令产生额外的数据?
8 bash  sudo  cron  echo  tail 

3
用不同文件中的另一列替换文件中一列中的匹配条目
我有两个制表符分隔的文件,如下所示: 文件1: NC_008146.1 WP_011558474.1 1155234 1156286 44173 NC_008146.1 WP_011558475.1 1156298 1156807 12 NC_008146.1 WP_011558476.1 1156804 1157820 -3 NC_008705.1 WP_011558474.1 1159543 1160595 42748 NC_008705.1 WP_011558475.1 1160607 1161116 12 NC_008705.1 WP_011558476.1 1161113 1162129 -3 NC_009077.1 WP_011559727.1 2481079 2481633 8 NC_009077.1 WP_011854835.1 1163068 1164120 42559 NC_009077.1 WP_011854836.1 1164127 1164636 7 文件2: NC_008146.1 GCF_000014165.1_ASM1416v1_protein.faa …
8 awk 

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.