Unix & Linux

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

1
引用bash数组值时,@和*有什么区别?
这个Bash指南说: 如果索引号是@或*,则引用数组的所有成员。 当我这样做时: LIST=(1 2 3) for i in "${LIST[@]}"; do echo "example.$i " done 给出:(example.1 example.2 example.3期望的结果)。 但是当我使用时${LIST[*]},我得到了example.1 2 3。 为什么? 编辑:使用printf时,@和*实际上给出相同的结果。
15 bash  array 

4
我如何找出cron为什么不执行我的工作?
我正在使用Ubuntu 14.04,并且cron守护程序正在运行: # ps ax | grep cron 822 ? Ss 0:00 cron 但它不执行任何作业。我以前收到这样的条目/var/log/syslog: 2014-05-04T11:47:01.839754+01:00 localhost CRON[29253]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )) 但现在没有与cron相关的条目。我也在/var/log/auth.log: 2014-05-04T11:47:01.839183+01:00 localhost CRON[29252]: pam_unix(cron:session): session opened for user root by (uid=0) 2014-05-04T11:47:13.495691+01:00 localhost CRON[29252]: pam_unix(cron:session): session closed for …
15 ubuntu  cron 

3
编写要在履历表上执行的系统服务
我的戴尔笔记本电脑的内核3.14 受此错误影响。作为解决方法,我编写了一个简单的脚本 / usr / bin /亮度修复: #!/bin/bash echo 0 > /sys/class/backlight/intel_backlight/brightnes (和由可执行:chmod +x /usr/bin/brightness-fix) 以及在启动时执行的调用它的系统服务: /etc/systemd/system/brightness-fix.service [Unit] Description=Fixes intel backlight control with Kernel 3.14 [Service] Type=forking ExecStart=/usr/bin/brightness-fix TimeoutSec=0 StandardOutput=syslog #RemainAfterExit=yes #SysVStartPriority=99 [Install] WantedBy=multi-user.target 并启用: systemctl enable /etc/systemd/system/brightness-fix.service 这就像一种魅力,我可以根据需要控制显示屏的亮度。问题出在笔记本电脑进入睡眠模式后恢复正常运行时(例如,当合上笔记本电脑的嘴唇时):亮度控制不再起作用,除非我手动执行上面的fisrt脚本:/usr/bin/brightness-fix 如何创建另一个像我上面的系统服务,以便在恢复时执行? 编辑: 根据下面的评论,我已经修改了我brightness-fix.service这样的: [Unit] Description=Fixes intel backlight control with Kernel 3.14 …
15 systemd  laptop 


4
zsh可以访问上次运行程序的标准输出吗?
我经常使用find或locate查找有关路径的信息。 (~) locate foobar.mmpz /home/progo/lmms/projects/foobar.mmpz 下一步通常是打开文件或以其他方式操作文件。在像上面这样的快乐情况下,我可以这样做: (~) ls `!!` ls `locate foobar.mmpz` /home/progo/lmms/projects/foobar.mmpz 但是,当有许多行输出时,没有人会太高兴,其中某些行可能不是路径或其他类似的东西。此外,重新运行可能浪费的命令也不是一件容易的事。 是否有办法连接zsh将stdout存储到数组中以供以后处理?毕竟,将流重定向到用户是Shell的工作。我在想它可以将前N行和后N行存储在变量中,以便像$?其他变量一样立即使用。 好的,这很酷:https : //unix.stackexchange.com/a/59704/5674。我现在正在询问有关zsh的专门知识(并将代码移植到zsh),以便在每次运行后都进行这种捕获。
15 terminal  zsh  output 

3
如何将已经转发的ssh密钥转发到tmux?
我正在从存储密钥的计算机通过SSH连接,然后转发到第二台计算机,然后尝试从tmux中使用密钥。输入tmux时,我似乎“松开”了转发。如何“再次转发”以便我可以在tmux中使用我的密钥? $ ssh [server] -o ForwardAgent=yes $ git pull # Succeeds. $ /bin/bash $ git pull # Still succeeds, despite new shell. $ exit $ tmux attach $ git pull # Permission denied (publickey)
15 shell  ssh  tmux 

2
GNU屏幕状态栏-如何使其显示Shell会话名称?
假设我在GNU屏幕中打开了几个名为bash1,bash2等的外壳“选项卡”(或屏幕?会话?)。我希望状态栏(即标题行)将名称显示为“ bash1 | bash2 | ..”,并明确标记当前打开的选项卡和最后一个打开的选项卡。 我该如何做到这一点.screenrc?



4
Ctrl-C与bash中的两个同时命令
我想在Linux机器上的bash中同时运行两个命令。因此,在我的./execute.shbash脚本中,我输入: command 1 & command 2 echo "done" 但是,当我想停止bash脚本并按Ctrl+时C,仅第二个命令停止。第一个命令保持运行。如何确保完整的bash脚本已停止?或者在任何情况下,如何停止两个命令?因为在这种情况下,无论我多按一次Ctrl+ C,命令都会继续运行,并且我不得不关闭终端。

2
在bash shell中的for循环内连接字符串变量
已关闭。这个问题需要细节或说明。它当前不接受答案。 想改善这个问题吗?添加细节并通过编辑此帖子来澄清问题。 6年前关闭。 #!/bin/bash names= find /home/devuser -name 'BI*' echo $names for name in {names[@]} do echo $name $var = $var$name done echo $var

2
GLOBIGNORE如何运作?
根据bash的手册页: GLOBIGNORE A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a pathname expansion pattern also matches one of the patterns in GLOBIGNORE, it is removed from the list of matches. 但是在实践中... $ bash --noprofile --norc bash-4.2$ touch …

2
mutt:将邮件保存到特定文件夹
我在Mutt中定义了几个文件夹: mailboxes "~/Mail/inbox" mailboxes "~/Mail/sent" mailboxes "~/Mail/archive" 我可以保存(移动)要存档的消息,方法是按s,然后?查看文件夹列表,然后archive从列表中进行选择。 由于我一直只想保存到archive,因此我想要一个宏,因此按会s自动将选定的消息保存到archive,而无需询问我。 有人可以帮忙吗? 编辑: 我现在有以下宏,以将消息保存到我的“存档”文件夹: macro index,pager S "<tag-prefix><save-message>=archive<enter>\ :set delete=yes<enter><sync-mailbox>:set delete=no<enter>" 问题是,邮件保留在标记为已删除的索引中。它们不会立即“同步”。其次,<enter>末尾的充当<display-message>,因此,当我按时S,我将进入当前消息的寻呼机。 以类似的方式,我试图trash在mutt中实现该文件夹。以下摘自Mutt MacroSamples set maildir_trash=yes set wait_key=no folder-hook . 'bind index q quit' folder-hook inbox 'macro index q ":unset maildir_trash;push \"T~D\\n<tag-prefix-cond>m=trash\\n<end-cond><quit>\"\n"' 但这也不起作用。笨蛋问我: Append messages to etmaildir_trash;push"T~D\n<tag-prefix-cond>m=trash\n<end-cond><quit>"/maildir_trash;push"T~D\n<tag-prefix-cond>m=trash\n<end-co ([yes]/no): 无论我按什么按钮,都不会发生任何事情(文件夹垃圾桶/ {cur,new,tmp}确实存在)
15 mutt 

4
/ home / <用户> /上的权限755
我想知道为什么默认情况下我的目录的/home/&lt;user&gt;/权限设置为755。这使其他用户可以进入目录并读取我家中的文件。有任何正当的理由吗? 我可以700为我的主目录和所有子目录设置权限吗,例如: chmod -R o-xw /home/&lt;user&gt;/ chmod -R g-xw /home/&lt;user&gt;/ 没有破坏任何东西? 另外,是否可以在我的家庭中设置权限,以便所有创建的新文件都具有600和目录700?

2
实际使用TCP_DEFER_ACCEPT?
我在网上仔细阅读了Apache httpd手册,并遇到了启用它的指令。在手册页中找到以下内容的描述tcp: TCP_DEFER_ACCEPT (since Linux 2.4) Allow a listener to be awakened only when data arrives on the socket. Takes an integer value (seconds), this can bound the maximum number of attempts TCP will make to complete the connection. This option should not be used in code intended to be …

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.