I am currently trying to see , all the files which are using /var mount.
With lsof | grep /var*
when Its displaying size in bytes. How can I display file size in MB.
Thank you.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityStarting with GNU Coreutils version 8.21 (released on Dec-2013), there is a new standard program called numfmt
(=number format).
It will do exactly what you want.
Example:
lsof | grep /var* | numfmt --field=8 --to=iec | head
The parameter --to
accepts iec
(where 1K=1024B) or si
(where 1K=1000). There are few additional options, more information here:
http://www.gnu.org/s/coreutils/numfmt .
(disclaimer: I wrote the initial implementation of numfmt
).
--field=7
is what you want for lsof
, which is the SIZE of file that the OP was looking for. Thanks.
Try this:
| awk '{$7=$7/1048576 "MB"; print}'
or shorter:
| awk '{$7=$7/1048576 "MB"}1'
You can use awk to convert bytes to MB.
Something like this should show size in MB.
lsof | grep /var* | awk '{for(i=1;i<=6;i++){printf "%s ", $i}; print $7/1048576 "MB" " "$8" "$9 }'
It will print all fields up to 7th field, which is then divided with 1048576 to get the size in MB, and then is shows remaining two fields.
lsof +d /var
instead ofgrep
ping.