How to get the percentage of memory free with a Linux command? [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I would like to get the available memory reported as a percentage using a Linux command line.
I used the free command, but that is only giving me numbers, and there is no option for percentage.

Using the free command:
% free
total used free shared buffers cached
Mem: 2061712 490924 1570788 0 60984 220236
-/+ buffers/cache: 209704 1852008
Swap: 587768 0 587768
Based on this output we grab the line with Mem and using awk pick specific fields for our computations.
This will report the percentage of memory in use
% free | grep Mem | awk '{print $3/$2 * 100.0}'
23.8171
This will report the percentage of memory that's free
% free | grep Mem | awk '{print $4/$2 * 100.0}'
76.5013
You could create an alias for this command or put this into a tiny shell script. The specific output could be tailored to your needs using formatting commands for the print statement along these lines:
free | grep Mem | awk '{ printf("free: %.4f %\n", $4/$2 * 100.0) }'

Related

How to log timestamp before every line in log? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I want to log memory usage every 5th second and hence I am using free -s 5 -m> memory.log
How to add timestamp before every lie in this log?
Expected output:
Tue Jan 21 06:50:44 UTC 2020
total used free shared buffers cached
Mem: 7809 6268 1540 0 57 3497
-/+ buffers/cache: 2713 5095
Swap: 0 0 0
Tue Jan 21 06:50:49 UTC 2020
total used free shared buffers cached
Mem: 7809 6268 1540 0 57 3497
-/+ buffers/cache: 2713 5095
Swap: 0 0 0
I found out that there is no single line command to do that and this can be achieved by writing and executing a script.
So the shell script is:
#!/bin/bash -e
echo " date time $(free -m | grep total | sed -E 's/^ (.*)/\1/g')" >> /var/log/memory_utilisation.log
while true; do
echo "$(date '+%Y-%m-%d %H:%M:%S') $(free -m | grep Mem: | sed 's/Mem://g')" >> /var/log/memory_utilisation.log
sleep 5
done

No space left on device [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I am getting the error "No space left on device" when i tried to scp some files to a centos machine,
tried to check:
[root#...]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol01 18G 18G 0 100% /
And when I do
du -sh / -> it gives only 5G
[... ~]$ df -i /
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/VolGroup00-LogVol01
4685824 209516 4476308 5% /
seems like file system is full.
How can i find which one is taking these much size?
Such difference between the output of du -sh and df -h may happen if some large file has been deleted, but is still opened by some process. Check with the command lsof | grep deleted to see which processes have opened descriptors to deleted files. You can restart the process and the space will be freed.
Maybe you are out of inodes. Try df -i
2591792 136322 2455470 6% /home
/dev/sdb1 1887488 1887488 0 100% /data
Disk used 6% but inode table full.
To list processes holding deleted files a linux system which has no lsof, here's my trick:
pushd /proc ; for i in [1-9]* ; do ls -l $i/fd | grep "(deleted)" && (echo -n "used by: " ; ps -p $i | grep -v PID ; echo ) ; done ; popd
You can execute the following commands
lsof / |grep deleted
kill the process id's, which free up the disk space.

Check what partition is used? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I'm working on a SBC6845 card with Linux on it:
I have 4 partitions installed:
Creating 5 MTD partitions on "atmel_nand":
0x000000000000-0x000000100000 : "Factory"
0x000000100000-0x000000300000 : "Kernel1"
0x000000300000-0x000000500000 : "Kernel2"
0x000000500000-0x000008280000 : "Rootfs1"
0x000008280000-0x000010000000 : "Rootfs2"
I want to make a shell script that display which partition is currently used but I don't see how.
the command "df -h" returns:
# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 178.8G 65.4G 104.3G 39% /
tmpfs 61.7M 0 61.7M 0% /dev/shm
tmpfs 61.7M 36.0K 61.7M 0% /tmp
and also fdisk doesn't work on this system.
Anyone have an idea how to resolve this?
So you want to know on which partition your script is currently located ? df can help you with this! You just have to give it the path to your script as an argument:
#!/bin/sh
df $0 | tail -1 | awk '{print $1}'
And sh myscript.sh gives me: /dev/sda1
Explanations:
df $0 outputs the partition in which myscript.sh is
tail -1 ignores the first line of df (name of the columns)
awk '{print $1}' returns the first column of df, which is the partition
I hope this is what you expected!

Reading entropy_avail file appears to consume entropy [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
The question have been asked in here http://www.gossamer-threads.com/lists/linux/kernel/1210167 but I don't see an answer.
AFAIK /proc/sys/kernel/random/entropy_avail should return the size of available entropy but should not consume it. At least I don't see any reason for that.
However, I have been noticing the same thing as OP for at least a year and now I executed in quick succession
% cat /proc/sys/kernel/random/entropy_avail
3918
% cat /proc/sys/kernel/random/entropy_avail
3447
% cat /proc/sys/kernel/random/entropy_avail
2878
% cat /proc/sys/kernel/random/entropy_avail
2377
% cat /proc/sys/kernel/random/entropy_avail
1789
% cat /proc/sys/kernel/random/entropy_avail
1184
% cat /proc/sys/kernel/random/entropy_avail
577
% cat /proc/sys/kernel/random/entropy_avail
161
% cat /proc/sys/kernel/random/entropy_avail
133
% cat /proc/sys/kernel/random/entropy_avail
171
a while later I did the same with the same result, so I'm pretty sure the depletion of entropy is caused by the cat command.
Can anyone explain why this happens?
Found an answer in here http://blog.flameeyes.eu/2011/03/entropy-broken
Starting a process consumes entropy

What is equivalent of Linux's 'free' command on FreeBSD v8.1 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
What is equivalent of Linux's 'free' command on FreeBSD v8.1?
I am calling 'free' from my application and reporting the results in my application's log file. What would be the replacement when porting to FreeBSD v8.1?
Here is a sample run of 'free' on Linux:
[centos4x32 ~] free
total used free shared buffers cached
Mem: 774452 733044 41408 0 98040 328880
-/+ buffers/cache: 306124 468328
Swap: 2031608 224 2031384
vmstat has default output which is similar in nature and takes many options that give extremely detailed information, eg vmstat -m
swapinfo would cover the swap part
top -d1 causes top to print one screen and exit, and the banner is very similar to free. Use top -d1 | head -n 7 to see only the banner
Maybe freecolor command is a choice. Install it:
# cd /usr/ports/sysutils/freecolor
# make install clean
Use it:
# freecolor
Physical : [#################################..] 94% (1907820/2018396)
Swap : [###################################] 100% (1048540/1048540)
# freecolor -m -o
total used free shared buffers cached
Mem: 1971 107 1863 0 0 0
Swap: 1023 0 1023
Please refer FreeBSD find out RAM size Including Total Amount of Free and Used Memory Size.
vmstat -s gives some more human-readable or script-parseable information, including listing the page size. Otherwise, it gives output in numbef of pages. With no options, vmstat gives a brief summary.
The vmstat command also exists on NetBSD.
just use old good htop
install htop
pkg install htop
to run
htop
Other option:
# vmstat fre
procs memory page faults cpu
r b w avm fre flt re pi po fr sr in sy cs us sy id
0 0 0 13475M 24M 689 1 2 0 344 394 14693 37734 60809 7 43 50
You can use this script.
# fetch http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
# mv freebsd-memory.pl.txt /usr/local/bin/free
# chmod +x /usr/local/bin/free
source: http://www.cyberciti.biz/faq/freebsd-command-to-get-ram-information/

Resources