Your Webhosting Questions
Answered by the Webhosting Experts
Tags
...
...

Linux Storage Analysis

Traversing storage drives in Linux can be intimidating task at first. In this article, we’ll cover some basic and advanced commands along with various third party tools you can use to help gather information regarding your system’s current status. These commands should cover all basic needs that you might require in order to evaluate the storage conditions of your Linux system and get a better understanding of your device.

Basic Commands to Evaluate Storage Conditions

The following commands will cover basic information regarding storage devices and their current usage conditions.

  • The following command will list drives in the system that are available along with their set mounting directories:

    lsblk

  • The following command will let you view the current disk usage by the filesystem along with the drive’s total size, amount used, usage %, and mounted directory for each:

    df -h

  • The following command will let you view the size of a particular directory (in this example the /backup directory):

    du -sh /backup

Advanced Commands to Evaluate Storage Condition

The following commands will help you take a deeper look into retrieving information regarding specific file and directory sizes. These are useful for determining which particular files or directories are taking the largest amount of space and will give you a good starting point in your system analysis.

  • The following command inspects the largest files and directories in a given directory:

    du -ahx / | sort -rh | head -15

    *Note: To modify the specific directory, enter it after the “-ahx” option. For example, du -ahx /home | sort -rh | head -15, will retrieve information from the /home directory.

    To evaluate and retrieve a specific number of files, modify the numeric value after the “head” string. For example, du -ahx /backup | sort -rh | head -60 , will retrieve 60 of the largest files and directories within /backup directory.

  • The following command can be used to retrieve a list of every file that is larger than 500MB in the directory of choice [*Note: the entire command is one line]:

    find / -type f -size +500M ! -path ‘*proc*’ ! -path ‘/home/virtfs*’ -exec ls -lh {} \;|awk ‘{ print “\033[32m”$NF “: \033[31m”$5″\033[0m” }’

    *Note: Directory can be modified here by changing it after the “find” syntax, for example, find /home2, will search within the /home2 directory.

    File size can be changed as well to suit your need by changing the value of “500M” to any value you’d like.

  • The following command can be used to retrieve a list of files that have recently changed [*Note: the entire command is one line]:

    find . -type f -exec stat -c ‘%Y %n’ {} \; | sort -nr | awk -v var=”20″ ‘NR==1,NR==var {print $0}’ | while read t f; do d=$(date -d @$t “+%b %d %T %Y”); echo “$d — $f”; done

Various Third-Party Packages to Visualize the Filesystem

The following are a couple of packages which can assist in your storage analysis by creating a visual representation of your filesystem, allowing you to traverse it via a user interface.

NCurses Disk Usage

This particular package, NCurses Disk Usage (or ncdu in your package manager), can be used if available within your package manager to help visualize and perform simple commands with files in your system. The keyboard arrows in ncdu can be used along with typing “?” for further assistance on which keys perform which functions.

Screenshot of the NCurses Disk Usage (ncdu) interface

Midnight Commander

Another useful command-line tool is Midnight Commander (or mc in your package manager), which allows you to view file sizes and modification time, along with having split screen for file transfers.

Screenshot of the Midnight Commander (MC) interface.

-written by Pascal Suissa

Need More Personalized Help?

If you have any further issues, questions, or would like some assistance checking on this or anything else, please reach out to us from your my.hivelocity.net account and provide your server credentials within the encrypted field for the best possible security and support.

If you are unable to reach your my.hivelocity.net account or if you are on the go, please reach out from your valid my.hivelocity.net account email to us here at: [email protected]. We are also available to you through our phone and live chat system 24/7/365.

Tags +
...