我有一个 bash 脚本,它处于可运行状态,用户空间中的 cpu 使用率为 100%。有没有一种方法可以更仔细地检查导致问题的原因,而不会终止进程,例如进行堆栈跟踪?
在安装 Windows 10 之前,当我按下 Git Bash 中的向下或向上箭头按钮时,我会得到以前输入的命令。但是现在当我关闭 Git Bash 时,我丢失了我曾经输入的所有命令。我如何取回这个?
我有练习,我必须删除所有文件,而不是jpeg.
我试过了find -type f |xargs file| grep -iv 'jpeg',但它不起作用。
我是新手bash和脚本。
我想写一个别名或脚本,这样每次我exit在命令行时,它都会记录我的命令历史。因为我尝试了很多新命令,而且我想回到文件中并对其进行评论,这样我可以更好地学习,而不仅仅是尝试命令然后完全忘记它们。
alias exit ="history > `date +%Y-%m-%d`.txt; exit"
Run Code Online (Sandbox Code Playgroud)
但是当我重新加载我的 bash 时,我得到:
-bash: alias: exit: not found
-bash: alias: =history > 2015-09-22.txt; exit: not found
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?我应该尝试编写一个带有 while 循环的脚本吗?
通常,我习惯于使用cd命令导航到 Linux 中的目录。现在,在终端中,我需要进入一个名为-.
我尝试使用 导航到目录cd -,但我被带到了上一个目录,这是正常行为。
如何导航到名为 的目录-?
我有一个在/tmp目录中创建几个文件的脚本
#!/bin/bash
touch /tmp/file1.txt
touch /tmp/file2.txt
Run Code Online (Sandbox Code Playgroud)
如何让脚本/tmp/在 Finder 中打开带有两个文件的目录file1.txt并file2.txt选中?
我知道我可以打开文件夹:
open /tmp/
Run Code Online (Sandbox Code Playgroud)
但它(显然)没有选择这两个文件。
假设我有这个简单的 C 程序,它向 shell 返回 4。
int main()
{
return 4;
}
Run Code Online (Sandbox Code Playgroud)
当我运行它,然后做echo $?,我会得到4,这是预期的
$ gcc foo.c && ./a.out
$ echo $?
4 <<<< expected
Run Code Online (Sandbox Code Playgroud)
但是当我执行以下操作时,我什么也没得到
$ gcc foo.c && ./a.out && echo $?
$ <<<< Nothing - WHY????
Run Code Online (Sandbox Code Playgroud) 出于审计和文档目的,我想找到一个命令,以便将给定 bash 会话中发生的所有事情都写入文件。
即,我想最终得到一个文件,该文件显示我运行的所有命令以及这些命令的所有输出。
我知道我可以使用历史文件(命令运行)获得一部分,通过重定向输出获得一部分。
但是,我觉得bash本身应该有这种能力,只是我没有找到。
例子:
> bash --some-kind-of-magic output.txt
$ cat file1.txt
this is the content of file1.txt
$ grep test file2.txt
this is the output of the command
$ exit
> cat output.txt
$ cat file1.txt
this is the content of file1.txt
$ grep test file2.txt
this is the output of the command
$ exit
Run Code Online (Sandbox Code Playgroud) 是否有其他程序或应用程序可以让您将以前执行的命令列表保存在缓存或类似的东西上,以便您可以按一个键并访问或搜索以前执行的命令列表?使用向上箭头返回寻找 scp 或 ffmpg 会浪费很多时间。