Articles in the Linux category

  1. Linux: Get a List of Al Disks and Their Size

    Sun 25 November 2012

    To get a list of all disk drives of a Linux system, such as this:

    Disk /dev/md0: 58.0 GB
    Disk /dev/md1: 2015 MB
    Disk /dev/md5: 18002.2 GB
    Disk /dev/sda: 60.0 GB
    Disk /dev/sdb: 60.0 GB
    Disk /dev/sdc: 1000.1 GB
    Disk /dev/sdd: 1000.1 GB
    Disk /dev/sde: 1000.1 GB
    Disk /dev/sdf: 1000.1 GB
    Disk /dev/sdg: 1000.1 GB
    Disk /dev/sdh: 1000.1 GB
    Disk /dev/sdi: 1000.1 GB
    Disk /dev/sdj: 1000.1 GB
    Disk /dev/sdk: 1000.1 GB
    Disk /dev/sdl: 1000.1 GB
    Disk /dev/sdm: 1000.1 GB
    Disk /dev/sdn: 1000.1 GB
    Disk /dev/sdo: 1000.1 GB
    Disk /dev/sdp: 1000.1 GB
    Disk /dev/sdq: 1000.1 GB
    Disk /dev/sdr: 1000.1 GB
    Disk /dev/sds: 1000.2 GB
    Disk /dev/sdt: 1000.2 GB
    Disk /dev/sdu: 1000.2 GB
    Disk /dev/sdv: 1000.2 GB
    

    You can use the following command:

    #!/bin/bash
    for x in `cat /proc/diskstats | grep -o 'sd.\|hd.\|md.' | sort -u`
    do 
        fdisk -l /dev/$x 2>/dev/nul| grep 'Disk /' | cut -d "," -f 1 
    done
    
    If you have any comments email me, see the About page for contact details.
  2. Script That Deletes Old Files to Keep Disk From Filling Up

    Fri 19 August 2011

    When a disk has no free space left, all kinds of trouble can occur.

    Therefore, I've created a script that monitors the used space of a volume and deletes the oldest file if a certain threshold is reached.

    The script will keep on deleting the oldest file present on disk until used capacity is below the threshold.

    So you can tell the script to monitor volume /storage and delete old files if the used capacity is bigger than 95 percent.

    The script works like this:

    ./deleteoldfiles.sh <mount point> <percentage>
    

    The mount point represents a volume or physical disk. The percentage represents the maxium used capacity threshold.

    The script reads the output of the 'df -h' command to determine 'disk' usage.

    Example:

    bash-3.2$ ./deleteoldfiles.sh /Volumes/usb 92
    
    DELETE OLD FILES 1.00
    
    Usage of 90% is within limit of 92 percent.
    

    How let's see what happens when the threshold is exceeded.

    bash-3.2$ sudo ./deleteoldfiles.sh /Volumes/usb 92

    DELETE OLD FILES 1.00
    
    Usage of 97% exceeded limit of 92 percent.
    Deleting oldest file /Volumes/usb/a/file02.bin
    Usage of 91% is within limit of 92 percent.
    

    Here you notice that an old file is deleted and that the script checks again if there is now enough free space. If not, another file would have been deleted.

    If you have a need for it, have fun. It was a fun little scripting exercise.

    The script works under Linux and Mac OS X.

    If you have any comments email me, see the About page for contact details.

Page 2 / 7