20
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コマンドラインでプロセスをインタラクティブに探してkillするワンライナー

Last updated at Posted at 2016-04-05

これ

ps aux | fzf | sed 's/  */ /g' | cut -d ' ' -f2 | xargs kill -9

fzfの部分はpecoとかpercolとかお好みのやつに。

ps auxでプロセス一覧を表示してfzfで選択し、sedで空白を一つにまとめてcutして2番目がPIDなのでkill -9に渡す。

頻繁に使うので自分はこんな風にエイリアスにしてる。

alias pskl="ps aux | fzf | sed 's/  */ /g' | cut -d ' ' -f2 | xargs kill -9"

tmuxの設定を反映させるときとかよく使うので便利。

シェルスクリプト覚えたてなのでもっと良い書き方あったらコメントで教えて下さい。

追記(2016/05/01)

awk使ってこうもかけるみたい

ps aux | fzf | awk '{ print \$2 }' | xargs kill -9

こっちの方がすっきりして好みでした。

おわり

20
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?