我可以在 ls 输出中同时获得 ctime 和 atime 吗?似乎我只能传递一个--time=ctime或--time=atime参数(第二个被忽略)。有没有其他办法?
如何将长命令包装到 bash 脚本文件中的下一行?
作为一个简单的例子,我想运行命令 pushd . && cd /foo/bar && ls && popd
从控制台我可以这样做:
pushd . \
&& cd /foo/bar \
&& ls \
&& popd
Run Code Online (Sandbox Code Playgroud)
这就结束了。但是脚本文件中的相同代码会产生错误。
你如何包装这些行以使其格式良好?
该站点表示,在 Linux 上,您可以space在终端命令之前添加一个以将其排除在.bash_history.
这似乎不适用于 Mac OS X。有谁知道在终端上执行单个命令而不将其保存到历史记录的方法?
我不想清除历史。

在 shell (bash) 中时 - 我想让 Ctrl-Backspace 绑定到“向后删除单词”。是否可以?
编辑:
我konsole在 KDE使用- 终端。
我正在寻找一行返回正在运行的进程的 pid 的行。
目前我有:
ps -A -o pid,cmd|grep xxx|head -n 1
这将返回拳头pid, command。我只需要输出中的第一个数字,而忽略其余部分。我想sed或awk会在这里提供帮助,但我对他们的经验有限。
另外,这还有一个问题,如果 xxx 没有运行,它会返回 grep 的 pid。
有一行真的很重要,因为我想重用输出来做其他事情,比如杀死那个进程。
我不明白 bash 如何评估单引号字符串中撇号字符的转义。
下面是一个例子:
$ echo ''\''Hello World'\'''
'Hello World' # works
$ echo '\'Hello World\''
> # expects you to continue input
Run Code Online (Sandbox Code Playgroud)
我试图寻找对此的解释,但什么也得不到。bash 在这里做什么?
在 bash emacs 模式下,无论如何要删除到前一个斜杠字符?例如,如果我输入命令cp /usr/local/bin/reallylongincorrectfolder /home/myname/reallylong_and_correct_path并只想删除reallylongincorrectfolder. 有什么快捷方式吗?在 bash 中,这对我来说是一个非常常见的场景。像dF<char>vi中的东西?
为什么有些 Linux 程序的输出既不去 STDOUT 也不去 STDERR?
实际上,我想知道如何可靠地捕获所有程序输出,无论它使用什么“流”。我的问题是有些程序似乎不让他们的输出被捕获。
一个例子是“时间”命令:
time sleep 1 2>&1 > /dev/null
real 0m1.003s
user 0m0.000s
sys 0m0.000s
Run Code Online (Sandbox Code Playgroud)
或者
time sleep 1 &> /dev/null
real 0m1.003s
user 0m0.000s
sys 0m0.000s
Run Code Online (Sandbox Code Playgroud)
为什么我两次都看到输出?我希望这一切都通过管道输入/dev/null。
时间使用的是什么输出流,我如何将其通过管道传输到文件中?
解决此问题的一种方法是创建一个Bash脚本,例如,combine.sh包含以下命令:
$@ 2>&1
Run Code Online (Sandbox Code Playgroud)
然后可以以正确的方式捕获 'time' 的输出:
combine.sh time sleep 1 &> /dev/null
Run Code Online (Sandbox Code Playgroud)
(没有看到输出 - 正确)
有没有办法在不使用单独的组合脚本的情况下实现我想要的?
我最近不得不 grep 获取可能已保存在文件中的密码。我不希望该行出现在 bash 历史记录中。
使用 grep 时,如何防止密码或其他敏感信息存储在 bash 历史记录中?例如,如何让 grep 从标准输入或控制台读取模式?
我尝试了以下命令:
$ wget -q --tries=10 --timeout=20 --spider http://google.com
Run Code Online (Sandbox Code Playgroud)
(来自this SO post。我想在bash中检查我的互联网连接。)
我得到以下输出:
Spider mode enabled. Check if remote file exists.
--2015-09-28 09:55:50-- http://google.com/
Connecting to 127.0.0.1:3128... connected.
Proxy request sent, awaiting response... 302 Found
Location: http://www.google.de/?gfe_rd=cr&ei=k_IIVreaN-yH8Qfe1Yu4CA [following]
Spider mode enabled. Check if remote file exists.
--2015-09-28 09:55:50-- http://www.google.de/?gfe_rd=cr&ei=k_IIVreaN-yH8Qfe1Yu4CA
Connecting to 127.0.0.1:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.
Run Code Online (Sandbox Code Playgroud)
似乎没问题,但是运行 …