Professional Documents
Culture Documents
Commands To Check Memory Usage On Linux
Commands To Check Memory Usage On Linux
The „du“ (Disk Usage) command line is a standard command under Unix and Linux. It is used to
list the disk space used by files on a machine and crucial for disk space management on unix and
linux systems. Several paramaters enable users to format and filter the results.
Using du is a good starting point when trying to clean up unused disk space under Unix.
Many smaller machines run Microsoft Windows. There is a wide range of graphical disk space
managers for Windows, but few will enable you to scan Linux and Unix servers without having
to resort to Samba. The Enterprise Edition of SpaceObServer will scan Unix and Linux servers
via SSH.
Using du
To analyze disk usage in a specific directory tree, simply enter the command line.
# du
Adding /* will show all directories and files at the top level of the file system:
# du -s /*
There are several ways to filter the information and gain the insights required to proceed.
Parameters
A wide range of parameters can be used to refine the results. Many flags can be used in
combination. This is a (by no means complete) selection of useful arguments.
#du -s
Display the disk space used by all files in the selected directory by adding -s. You cannot limit
the folder depths while using this argument.
r# du -s /*
#du -h
Adding the parameter -h shows the results in a human-readable format: It adds size information
in Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, and Petabyte.
#du -c
Use the -c argument to sum up the used disk space in the last line of the results.
#du -ch /var
# du -hs *
The disk space manager TreeSize Professional provides similar information in the „Details“
view.
Sort Results
Add | sort to the command line to sort the output. | sort -rh sorts recursively and displays the
biggest sizes on top.
# du -s /* | sort -rh
# df
The same as above, but it also displays information of dummy file systems along with all the file
system disk usage and their memory utilization.
# df -a
The df command provides an option to display sizes in Human Readable formats by using ‘-h’
(prints the results in human readable format (e.g., 1K 2M 3G)).
# df -h
# df -k
# df -m
# df -h
# fdisk -l
If you would like to view all commands which are available for fdisk. Simply use the following
command by mentioning the hard disk name such as /dev/sda as shown below. The following
command will give you output similar to below.
# fdisk /dev/sda
Type ‘m‘ to see the list of all available commands of fdisk which can be operated on /dev/sda
hard disk. After, I enter ‘m‘ on the screen, you will see the all available options for fdisk that you
can be used on the /dev/sda device.
# fdisk /dev/sda
# fdisk /dev/sda
From the command mode, enter ‘p‘ instead of ‘m‘ as we did earlier. As I enter ‘p‘, it will print
the specific /dev/sda partition table.
# fdisk /dev/sda
Next, enter ‘d‘ to delete any given partition name from the system. As I enter ‘d‘, it will prompt
me to enter partition number that I want to delete from /dev/sda hard disk. Suppose I enter
number ‘4‘ here, then it will delete partition number ‘4‘ (i.e. /dev/sda4) disk and shows free
space in partition table. Enter ‘w‘ to write table to disk and exit after making new alterations to
partition table. The new changes would only take place after next reboot of system. This can be
easily understood from the below output.
If you’ve free space left on one of your device say /dev/sda and would like to create a new
partition under it. Then you must be in fdisk command mode of /dev/sda. Type the following
command to enter into command mode of specific hard disk.
# fdisk /dev/sda
After entering in command mode, now press “n” command to create a new partition
under /dev/sda with specific size. This can be demonstrated with the help of following
given output.
While creating a new partition, it will ask you two options ‘extended‘ or ‘primary‘ partition
creation. Press ‘e‘ for extended partition and ‘p‘ for primary partition. Then it will ask you to
enter following two inputs.
After the new partition is created, don’t skip to format the newly created partition using
‘mkfs‘ command. Type the following command in the terminal to format a partition.
Here /dev/sda4 is my newly created partition.
5194304
If you’ve deleted a logical partition and again recreated it, you might notice ‘partition out of
order‘ problem or error message like ‘Partition table entries are not in disk order‘.
For example, when three logical partitions such as (sda4, sda5 and sda6) are deleted, and new
partition created, you might expect the new partition name would be sda4. But, the system would
create it as sda5. This happens because of, after the partition are deleted, sda7 partition had been
moved as sda4 and free space shift to the end.
To fix such partition order problems, and assign sda4 to the newly created partition, issue the ‘x‘
to enter an extra functionality section and then enter ‘f‘ expert command to fix the order of
partition table as shown below.
After, running ‘f‘ command, don’t forget to run ‘w‘ command to save and exit from fdisk
command mode. Once it fixed partition table order, you will no longer get error messages.
By default, fdisk command shows the boot flag (i.e. ‘*‘) symbol on each partition. If you want to
enable or disable boot flag on a specific partition, do the following steps.
[root@tecmint ~]# fdisk /dev/sda
Press ‘p‘ command to view the current partition table, you see there is a boot flag (asterisk (*)
symbol in orange color) on /dev/sda1 disk as shown below.