If you have installed fzf using Chocolatey on your Windows machine and are looking for a streamlined way to find and kill processes similar to the Unix kill command, you have come to the right place.
What is fzf?
fzf (fuzzy finder) is a command-line fuzzy finder written in Go by Junegunn Choi. fzf is highly flexible and can be used for many tasks such as filtering, searching, and launching files, grep, and processes. It's an excellent tool for developers, sysadmins, or anyone looking to improve their command-line productivity.
Installing fzf on Windows
You can install fzf on Windows using two popular package managers, Chocolatey and Scoop. However, in this article, we'll focus on Chocolatey since it's the one mentioned in your question. If you haven't installed Chocolatey yet, you can find installation instructions at https://chocolatey.org/install.
Once Chocolatey is installed, you can install fzf using the following command:
choco install fzf
Finding and Killing Processes Using fzf in CMD
fzf does not have a built-in "kill" command like Unix equivalents, but you can quickly find and kill processes using a combination of fzf, Windows Tasklist, and Taskkill commands.
Step 1: Find PIDs Using fzf
You can search for and list PIDs of running processes by using fzf in combination with the Windows Tasklist command.
tasklist | findstr /B /R ".exe" | fzf --tac --delimiter " " --nth 2 --preview "tasklist /FI \"PID eq {}\" /FO CSV"
Here's what this command does:
- Runs the 'tasklist' command to display running processes
- Pipes the output to 'findstr' to filter only .exe processes
- Pipes the output to 'fzf' to enable fuzzy searching through the process list
- Fzf options:
- '--tac': Reverse the order of the input
- '--delimiter " "': Sets a space as the column delimiter
- '--nth 2': Selects the second column (PID column)
- '--preview': Displays the Tasklist preview for selected PIDs
Step 2: Kill Selected Process
Once you have selected the process using fzf, you can kill the process using the 'taskkill' command. You can pass the PID to this command with a bit of scripting magic.
tasklist | findstr /B /R ".exe" | fzf --tac --delimiter " " --nth 2 | awk '{print "taskkill /F /PID " $1}' | cmd
Here's what this command does:
- Runs the same command from Step 1
- Pipes the output to the 'awk' command
- Awk command:
- Prints a 'taskkill' command with the PID appended
- Pipes the output to 'cmd' to execute the taskkill command
- Find and kill Windows processes using fzf by combining fzf, Windows Tasklist, and Taskkill commands
- Use the 'tasklist' and 'findstr' commands to list .exe processes
- Use 'fzf' to enable fuzzy searching through the process list
- Use 'awk' and 'cmd' commands to construct and execute the 'taskkill' command