首页 \ 问答 \ 如何关闭所有终端,无论是从bash脚本运行什么或iPython(How to close all terminal either running nothing or iPython from a bash script)

如何关闭所有终端,无论是从bash脚本运行什么或iPython(How to close all terminal either running nothing or iPython from a bash script)

我运行的终端数量趋于激增,其中大多数并不重要,我的意思是他们无论是什么都没有运行或者是iPython。

在我之前的一个问题中, 如何使用bash脚本关闭所有终端,该脚本在每个终端中有效地按下Cntrl + Shift + Q,名为webb的用户解释了如何关闭所有没有子进程的终端:

pgrep bash | xargs -n1 pstree -p -c | grep -v \- | grep -o '[0-9]\+' | xargs kill

我想稍微调整这个bash脚本,以便选择运行iPython的进程的ID。

到目前为止我尝试过的

举个例子,一个输出

pgrep bash | xargs -n1 pstree -p -c

看起来像这样:

bash(793)───ipython(847)───{ipython}(854)
bash(1787)───ipython(2061)───{ipython}(2062)
bash(6018)───ipython(6052)───{ipython}(6053)
bash(6810)───python(13796)───python(15653)───{python}(15657)
bash(7197)───docker-compose(20923)───docker-compose(20924)─┬─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           └─{docker-compose}(2+
bash(8629)───ipython(19746)─┬─{ipython}(19748)
                            ├─{ipython}(19762)
                            ├─{ipython}(19763)
                            ├─{ipython}(19764)
                            ├─{ipython}(19765)
                            ├─{ipython}(19766)
                            ├─{ipython}(19767)
                            └─{ipython}(19768)
bash(9945)───ipython(31376)─┬─{ipython}(31377)
                            ├─{ipython}(31391)
                            ├─{ipython}(31392)
                            ├─{ipython}(31393)
                            ├─{ipython}(31394)
                            ├─{ipython}(31395)
                            ├─{ipython}(31396)
                            └─{ipython}(31397)
bash(15906)───ipython(15974)───{ipython}(15976)
bash(16302)───xargs(19015)───pstree(19027)
bash(17377)───ipython(17407)───{ipython}(17409)
bash(17797)
bash(22210)───node(26380)─┬─{V8 WorkerThread}(26382)
                          ├─{V8 WorkerThread}(26383)
                          ├─{V8 WorkerThread}(26384)
                          ├─{V8 WorkerThread}(26385)
                          ├─{node}(26405)
                          ├─{node}(26406)
                          ├─{node}(26407)
                          └─{node}(26408)
bash(32331)───ipython(32359)───{ipython}(32361)

我想选择不运行任何进程的pids - 在本例中为17797 - 以及运行ipython进程。 据我了解,我想替换命令

grep -v \-

在第二个管道之后,它选择每个没有连字符的行,到一个模式,选择这样的行或包含bashipython 。 作为我尝试的第一步(基于教程https://www.cyberciti.biz/faq/grep-regular-expressions/

pgrep bash | xargs -n1 pstree -p -c | grep -v '(\-|ipython)'

但这似乎不起作用,因为输出包含例如docker-compose的行。 关于如何使这项工作的任何想法?


The number of terminals I run tends to proliferate, and most of them are not important, by which I mean they are running either nothing or iPython.

In one of my previous questions, How to close all terminals with a bash script that effectively presses Cntrl+Shift+Q in each terminal, a user named webb explained how to close all terminals with no subprocesses:

pgrep bash | xargs -n1 pstree -p -c | grep -v \- | grep -o '[0-9]\+' | xargs kill

I would like to adapt this bash script somewhat to also select the IDs of processes running iPython.

What I've tried so far

As an example, one output of

pgrep bash | xargs -n1 pstree -p -c

looks like this:

bash(793)───ipython(847)───{ipython}(854)
bash(1787)───ipython(2061)───{ipython}(2062)
bash(6018)───ipython(6052)───{ipython}(6053)
bash(6810)───python(13796)───python(15653)───{python}(15657)
bash(7197)───docker-compose(20923)───docker-compose(20924)─┬─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           ├─{docker-compose}(2+
                                                           └─{docker-compose}(2+
bash(8629)───ipython(19746)─┬─{ipython}(19748)
                            ├─{ipython}(19762)
                            ├─{ipython}(19763)
                            ├─{ipython}(19764)
                            ├─{ipython}(19765)
                            ├─{ipython}(19766)
                            ├─{ipython}(19767)
                            └─{ipython}(19768)
bash(9945)───ipython(31376)─┬─{ipython}(31377)
                            ├─{ipython}(31391)
                            ├─{ipython}(31392)
                            ├─{ipython}(31393)
                            ├─{ipython}(31394)
                            ├─{ipython}(31395)
                            ├─{ipython}(31396)
                            └─{ipython}(31397)
bash(15906)───ipython(15974)───{ipython}(15976)
bash(16302)───xargs(19015)───pstree(19027)
bash(17377)───ipython(17407)───{ipython}(17409)
bash(17797)
bash(22210)───node(26380)─┬─{V8 WorkerThread}(26382)
                          ├─{V8 WorkerThread}(26383)
                          ├─{V8 WorkerThread}(26384)
                          ├─{V8 WorkerThread}(26385)
                          ├─{node}(26405)
                          ├─{node}(26406)
                          ├─{node}(26407)
                          └─{node}(26408)
bash(32331)───ipython(32359)───{ipython}(32361)

I'd like to select the pids of processes running nothing - in this case 17797 - and processes running ipython. As I understand it, I would like to replace the command

grep -v \-

after the second pipe, which selects every line without hyphens in it, to a pattern which select either such lines or lines containing both bash and ipython. As a first step I tried (based on the tutorial https://www.cyberciti.biz/faq/grep-regular-expressions/)

pgrep bash | xargs -n1 pstree -p -c | grep -v '(\-|ipython)'

but this seems not to work as the output contains the lines with docker-compose, for example. Any ideas on how to make this work?


原文:https://stackoverflow.com/questions/41598129
更新时间:2022-05-02 10:05

最满意答案

看起来你想要git checkout master然后git cherry-pick lG1来获得只提交给master的提交。 最后,你可以再次git push -f origin master


更新:基于OP的注释,看起来我们想要将提交lF1lG1 ,这样它们看起来就像一次提交引入了更改,而lF1lG1删除了凭据。 这可以通过从以下命令开始来完成。

git checkout abc
git rebase -i lE1

在显示的编辑器中,将提取更改为提交lG1并保存文件并退出编辑器。 浏览剩下的菜单,然后你应该得到你想要的历史记录,然后你可以快进合并到master


It looks like you want git checkout master and then git cherry-pick lG1 to get that commit only onto master. Finally, you can once more git push -f origin master.


Update: Based on the OP's comments, it looks like we want to squash together the commits lF1 and lG1, so that they look like one single commit which introduces the changes and lF1 with the credentials removed in lG1. This can be accomplished by starting with the following commands.

git checkout abc
git rebase -i lE1

In the editor that shows up, change the pick to squash for the commit lG1 and the save the file and quit the editor. Go through the remainder of the menus and then you should end up with the history you want, which you can then fast-forward merge into master.

相关问答

更多
  • Git只跟踪已提交的状态,因此您可以通过使用git reflog (下例中的egbtxt)查找来检查您的“消息”修订版。 $ git log --pretty=oneline 6db772f6672b2d418e3228f2f9c95032e150d216 messsage d8d4f93864df75f6e1ccc438db65809f2cb34330 Some prev commit [git: master] $ ls a.txt b.txt $ git checkout d8d4f93864 ...
  • 通过执行git checkout 203914 ,您已离开分支master ,现在处于所谓的“分离的HEAD”状态。 为了保留您的更改,您需要执行git checkout master ,然后创建新的提交。 如果您已经在分支上创建了提交,那么您可以使用reflog子命令找到它: $ git reflog ... 3aa60dd HEAD@{1}: commit: this commit is missing from master ... 如果您在reflog中找到提交,那么您可以直接将其应用于maste ...
  • 实际上,在设计中,在git中删除提交是相当困难的。 人们认为删除提交的许多命令(如rebase或reset)实际上只是使这些提交“无法访问” - 导致各种命令和工具的默认输出排除它们。 删除提交的理由保证成本是相对罕见的。 有时提交包含敏感信息(但是,在这种情况下,几乎总是最好考虑被泄露的信息,无论您是否努力从回购中删除它)。 也许提交包含过大的二进制文件,这些文件在任何其他提交中都不存在,使repo膨胀。 如果只是归结为想要“隐藏”一个“错误”,那么回购看起来很完美,我就不会浪费时间。 但是,如果您确实要 ...
  • 您已切换到create-view分支。 这就是您无法看到更改的原因。 要切换回master运行, git checkout master 希望您的所有更改都应该回来。 如果你的分支是一些其他名称。 只需检查git branch ,这将列出所有本地分支。 然后你应该可以切换使用, git checkout You have switched to create-view branch. That is the reason you are not able to see your cha ...
  • 存储您的更改: git stash save 做你的更新 git checkout -f $f2 取消您的更改 git stash pop 进行分析...... Stash your changes: git stash save Do your update git checkout -f $f2 Unstash your changes git stash pop Perform analysis...
  • 我不知道您使用的是哪种GUI工具。 我总是使用CLI。 但理论是一样的。 创建一个新的分支“branchA”,引用最新的提交98ea8a1d 硬重置当前分支“feature / RPG ......”提交f6f69dc1 因此,最后两个提交受branchA保护。 并且当前分支将回滚到f6f69dc1。 你可以从f6f69dc1做些事情。 I don't know which GUI tool you are using. I always use CLI. But the theory is the sam ...
  • 首先,您需要解析指向上一次提交的表达式 。 然后,您可以签出生成的提交ID。 例如: ObjectId previousCommitId = git.getRepository().resolve( "HEAD^" ); git.checkout().setName( previousCommitId ).call(); 请注意,签出提交会分离HEAD 。 First, you need to resolve the expression that points to the previous commi ...
  • 如果它靠近分支或标签,则使用^或~表示法,例如origin/master^^^ , origin/master~3 (在origin/master之前的三次提交) 祖先参考书 - Git Book 顺便说一句 - 不要混淆XYZ~2(从XYZ返回2次)和XYZ ^ 2(多次/合并提交XYZ的第二次父级) 使用“Short-SHA” - 哈希的唯一前缀(必须至少有4个字符并且唯一 - 我通常倾向于使用6个字符): Git工具 - 修订版选择 - Git Book https://stackoverflow.c ...
  • 看起来你想要git checkout master然后git cherry-pick lG1来获得只提交给master的提交。 最后,你可以再次git push -f origin master 。 更新:基于OP的注释,看起来我们想要将提交lF1和lG1 ,这样它们看起来就像一次提交引入了更改,而lF1在lG1删除了凭据。 这可以通过从以下命令开始来完成。 git checkout abc git rebase -i lE1 在显示的编辑器中,将提取更改为提交lG1并保存文件并退出编辑器。 浏览剩下的菜 ...
  • 有一种方法,但存在潜在的问题。 标签名称标识提交。 更具体和精确地,标签名称如v2.1是完全限定引用名称refs/tags/v2.1的简短版本,并且任何Git引用标识某些Git对象。 所有分支名称(例如master , refs/heads/master缩写)都被约束为仅识别提交对象。 标记名称通常标识提交对象-Git将其称为轻量级标记 - 或带注释的标记对象,然后继续识别提交。 在任何一种情况下, 特殊的gitrevisions语法 name ^{commit}指的是特定的提交,如果你需要它(通常你不要G ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)