lsof icon indicating copy to clipboard operation
lsof copied to clipboard

[FEATURE] Human readable output for sizes

Open ThomasFaivre opened this issue 3 years ago • 0 comments

Hello,

Is your feature request related to a problem? Please describe. I was searching for deleted files still opened and therefore using disk space. I was using the following command:

lsof -w -X | grep deleted | less

Files were quite large and plentiful. e.g.:

sudo      2923214                               root    8r      REG              254,0    11567160   60295266 /var/lib/sss/mc/initgroups (deleted)

Reading "11567160" is not really easy with that many files.

Describe the solution you'd like An option ike -H to convert byte sizes into human readable size (kB, MB, GB, ...)

# lsof -w -X -H | grep deleted | less
sudo      2923214                               root    8r      REG              254,0    12M   60295266 /var/lib/sss/mc/initgroups (deleted)

Describe alternatives you've considered I tried piping to numfmt but since some columns can be empty, I cannot provide a reliable --field option (same goes for awk):

# lsof -w -X | grep deleted | numfmt --field=7 --to=iec | head
numfmt: invalid number: ‘REG’
sssd        662                             root   14r      REG              253,0        10M   20465630 /var/lib/sss/mc/initgroups (deleted)
[...]

Many lines were not displayed with this solution due to the 'REG' issue.

I also played with -F option but it splits over several lines unless using the -F0, but even with this, it is not very human friendly (duh! It's for programs).

Additional context I was trying to follow instructions from this StackEchange thread: https://unix.stackexchange.com/questions/253321/how-to-display-size-human-readable-in-lsof-grep-var

But it seems it does not work anymore (I don't know when empty columns appeared in lsof) Sadly, the thread is closed so even if the option I suggest is added, or if you have an already usable solution for my problem, we cannot add the solution to the thread :/

Thank you!

ThomasFaivre avatar Oct 06 '22 11:10 ThomasFaivre