3 ms·
For finding what uses a file, I'm an 'fuser' kid but lsof is fine too. Using posh right now, so had to make my own: function fuser($relativeFile){ $f
by nailer 10y ago
For finding what uses a file, I'm an 'fuser' kid but lsof is fine too. Using posh right now, so had to make my own:
function fuser($relativeFile){
$file = Resolve-Path $relativeFile
foreach ( $Process in (Get-Process)) {
foreach ( $Module in $Process.Modules) {
if ( $Module.FileName -like "$file*" ) {
$Process | select id, path
}
}
}
}
In use:
> fuser .\node_modules\
Id Path
-- ----
2660 C:\Program Files\nodejs\node.exe
Since it's object pipelining, you can:
> fuser .\node_modules\ | kill
- smhenderson 10y agoI find myself using lsof for it's ability to show me what TCP sockets are in use more than what actual files are open. lsof | grep TCP
- Terr_ 10y agoFor that I often use: netstat --ip -a -p Those particular options mean to show just IP ports (UDP/TCP), in all statuses (active, listening) and to display the local process which is involved.