L’aide

Display information about physical and virtual memory on MAC OSX.
In bytes by default.

The calculation for the physical memory is extracted from the results of
the command vm_stat (which returns the results in blocksize). The
imprecision resulting from the transformation in bytes (number_of_blocks *
block_size, the default value of the calculations) will be between 0 and
the size of the block.
The calculation for virtual memory is taken from the "top" command.
The imprecision here is linked to the unit of reference of the "top"
command: kilo, mega, giga.
Calculations are made using "awk" that respects rounded (as opposed
to "bc"). "awk" is also quicker than "bc".

This command, with its with friendly and highly configurable display
is suitable for use oriented end user. For a command with raw display,
oriented developper, system administrator, etc., with less computation,
but also less precise, see free-like-raw.sh.
http://myblog.robert.sebille.name/article29.html

-s --swap Display only the swap. By default, the script displays only
the physical memory. (The call to "top" command to evaluate
virtual memory is more time intensive than the call to
"vm_stat".)
-v --verbose Display results for virtual AND physical memory.
-k --kilo Display in kilobytes. Integer. (Here, the decimals have no
sense given the transformation calculation in bytes and
imprecision that results.)
-m --mega Display in megabytes. Decimals have little meaning given
the imprecision, but they are possible. -d3 will show 3
decimal places, etc.
-g --giga Display in gigabyte. Here, the maximum imprecision is
reduced relative to the selected unit. The decimals make
sense and are necessary for a meaningful display. -d7 will
show 7 décimal places, etc.
-d[0-9] Display from 0 to 9 decimal places. Only possible with-m or-g.
-q --quiet Prevents display on stdout.

Display raw information about physical and virtual memory on MAC OSX.
In bytes by default.

The calculation for the physical memory is extracted from the results of
the command vm_stat (which returns the results in blocksize). The
imprecision resulting from the transformation in bytes (number_of_blocks *
block_size, the default value of the calculations) will be between 0 and
the size of the block.
The calculation for virtual memory is taken from the "top" command.
The imprecision here is linked to the unit of reference of the "top"
command: kilo, mega, giga.
Calculations are made using "awk" that respects rounded (as opposed
to "bc"). "awk" is also quicker than "bc".

This command is suitable for use oriented developper, system administrator,
etc. For a command with friendly and highly configurable display, more
precise, but with more calculations, see:
free-like.sh. http://myblog.robert.sebille.name/article29.html

-s --swap Display only the swap. By default, the script displays only
the physical memory. (The call to "top" command to evaluate
virtual memory is more time intensive than the call to
"vm_stat".)
-v --verbose Display results for virtual AND physical memory.
-k --kilo Display in kilobytes. Integer.
-m --mega Display in megabytes. Integer.
-g --giga Display in gigabyte. Integer.
-q --quiet Prevents display on stdout.

Les scripts à télécharger

Commande bash free-like.sh pour MAC OSX

Version 1.0.3

Commande bash free-like-raw.sh pour MAC OSX

Version 1.1.1

Le code

free-like.sh

#!/bin/bash

##########################################################################################
# Free-like command for MAC OSX #
##########################################################################################
# Copyright 1992-2013 The FreeBSD Project. All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without modification #
# are permitted provided that the following conditions are met: #
# #
# 1) Redistributions of source code must retain the above copyright notice, #
# this list of conditions and the following disclaimer. #
# 2) Redistributions in binary form must reproduce the above copyright notice, #
# this list of conditions and the following disclaimer in the documentation #
# and/or other materials provided with the distribution. #
# #
# THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR #
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT #
# SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, #
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT #
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR #
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, #
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) #
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY #
# OF SUCH DAMAGE. #
# #
# The views and conclusions contained in the software and documentation are those of the #
# authors and should not be interpreted as representing official policies, either #
# expressed or implied, of the FreeBSD Project. #
# #
# Authors: Robert Sebille, may 2013 #
##########################################################################################

echo -e "\tThe calculation for the physical memory is extracted from the results of"
echo -e "\tthe command vm_stat (which returns the results in blocksize). The"
echo -e "\timprecision resulting from the transformation in bytes (number_of_blocks *"
echo -e "\tblock_size, the default value of the calculations) will be between 0 and"
echo -e "\tthe size of the block."
echo -e "\tThe calculation for virtual memory is taken from the \"top\" command."
echo -e "\tThe imprecision here is linked to the unit of reference of the \"top\""
echo -e "\tcommand: kilo, mega, giga."
echo -e "\tCalculations are made using \"awk\" that respects rounded (as opposed"
echo -e "\tto \"bc\"). \"awk\" is also quicker than \"bc\".\n"

echo -e "\tThis command, with its with friendly and highly configurable display"
echo -e "\tis suitable for use oriented end user. For a command with raw display,"
echo -e "\toriented developper, system administrator, etc., with less computation,"
echo -e "\tbut also less precise, see free-like-raw.sh."
echo -e "\thttp://myblog.robert.sebille.name/article29.html\n"

echo -e "\t-s --swap\tDisplay only the swap. By default, the script displays only"
echo -e "\t\t\tthe physical memory. (The call to \"top\" command to evaluate"
echo -e "\t\t\tvirtual memory is more time intensive than the call to"
echo -e "\t\t\t\"vm_stat\".)"

##########################################################################################
# Free-like-raw command for MAC OSX #
##########################################################################################
# Copyright 1992-2013 The FreeBSD Project. All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without modification #
# are permitted provided that the following conditions are met: #
# #
# 1) Redistributions of source code must retain the above copyright notice, #
# this list of conditions and the following disclaimer. #
# 2) Redistributions in binary form must reproduce the above copyright notice, #
# this list of conditions and the following disclaimer in the documentation #
# and/or other materials provided with the distribution. #
# #
# THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR #
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT #
# SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, #
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT #
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR #
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, #
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) #
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY #
# OF SUCH DAMAGE. #
# #
# The views and conclusions contained in the software and documentation are those of the #
# authors and should not be interpreted as representing official policies, either #
# expressed or implied, of the FreeBSD Project. #
# #
# Authors: Robert Sebille, may 2013 #
##########################################################################################