如何关闭所有终端,无论是从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 \-
在第二个管道之后,它选择每个没有连字符的行,到一个模式,选择这样的行或包含
bash
和ipython
。 作为我尝试的第一步(基于教程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 runningipython
. As I understand it, I would like to replace the commandgrep -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
andipython
. 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
最满意答案
看起来你想要
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
并保存文件并退出编辑器。 浏览剩下的菜单,然后你应该得到你想要的历史记录,然后你可以快进合并到master
。It looks like you want
git checkout master
and thengit cherry-pick lG1
to get that commit only onto master. Finally, you can once moregit push -f origin master
.
Update: Based on the OP's comments, it looks like we want to squash together the commits
lF1
andlG1
, so that they look like one single commit which introduces the changes andlF1
with the credentials removed inlG1
. 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
tosquash
for the commitlG1
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 intomaster
.
相关问答
更多-
Git没有提交文件 - 现在`git checkout HEAD`缺少文件(Git did not commit a file - Now `git checkout HEAD` is missing files)[2022-01-16]
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膨胀。 如果只是归结为想要“隐藏”一个“错误”,那么回购看起来很完美,我就不会浪费时间。 但是,如果您确实要 ...
-
由于“git fetch && git checkout”导致恢复提交丢失(restore commit lost due to “git fetch && git checkout”)[2023-10-08]
您已切换到create-view分支。 这就是您无法看到更改的原因。 要切换回master运行, git checkout master 希望您的所有更改都应该回来。 如果你的分支是一些其他名称。 只需检查git branch ,这将列出所有本地分支。 然后你应该可以切换使用, git checkoutYou have switched to create-view branch. That is the reason you are not able to see your cha ... -
Git checkout每次提交(Git checkout each commit)[2023-07-09]
存储您的更改: 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... -
Checkout / Rollback特定提交ID GIT(可能重复)(Checkout/Rollback specific commit ID GIT (Possibly Duplicated))[2023-11-22]
我不知道您使用的是哪种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 ... -
JGit checkout上次提交(JGit checkout previous commit)[2022-11-13]
首先,您需要解析指向上一次提交的表达式 。 然后,您可以签出生成的提交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 ...