Pages

Tuesday, March 11, 2014

truncate deleted files from lsof

$ lsof|gawk '$4~/txt/{next};/REG.*\(deleted\)$/{printf ">/proc/%s/fd/%d\n", $2,$4}'

While the posted solution works, I'm a bit uneasy about the "%d" part. This would be hyper-correct approach:


lsof|gawk '$4~/txt/{next};/REG.*\(deleted\)$/{sub(/.$/,"",$4);printf ">/proc/%s/fd/%s\n", $2,$4}'

Oh, and you gotta pipe the result to sh if you want it to actually trim the files. ;)


Btw, this approach also removes false negatives (OP's command skips any deleted files with "txt" in their name).




commandlinefu.com


by David Winterbottom (codeinthehole.com)






from All commands http://ift.tt/1enILgJ

No comments:

Post a Comment