You are Here:
Linux Lite 7.0 RC1 Released - See Release Announcement Section

USB drive Storage Summary

Author (Read 8286 times)

0 Members and 1 Guest are viewing this topic.

Re: USB drive Storage Summary
« Reply #3 on: November 29, 2014, 05:56:50 PM »


  • Forum Regular
  • ***
  • 212
  • Reputation: 26
  • Linux Lite Enthusiast
    • View Profile
Not sure if this is in LL 2.0 or not but in 2.2 beta you can also right-click on the file and select 'Make file executable'.

misko: Another fantastic script! Keep 'em coming.

Re: USB drive Storage Summary
« Reply #2 on: November 29, 2014, 01:41:47 PM »


  • Friganeer
  • Platinum Level Poster
  • **********
  • 1255
  • Reputation: 139
    • View Profile

  • CPU: Intel Core2 Duo U9600

  • MEMORY: 4Gb

  • VIDEO CARD: Intel Mobile 4
Testing on 2 gig Kingston Data Traveler with some Windows And linux Driver files I am going to use on a Wireless Legacy IBM M41 Desktop I am setting up .

usbinform text doc contents below

Code: [Select]
PE32 executable (DLL) (GUI) Intel 80386
Little-endian UTF-16 Unicode text
MS Windows icon resource - 2 icons
PDF document
InstallShield CAB
C source
ISO-8859 text
PC bitmap
ASCII text
Zip archive data
Bourne-Again shell script
gzip compressed data
PE32 executable (GUI) Intel 80386
Composite Document File V2 Document
PE32 executable (native) Intel 80386
DOS batch file
JPEG image data
PE32+ executable (native) x86-64

usbinform1 text doc contents below

Code: [Select]
867.81 KiB
54.51 KiB
2.11 KiB
1.64 MiB
22.44 MiB
2.73 KiB
69.12 KiB
3.30 KiB
344.03 KiB
35.02 MiB
3.03 KiB
2.09 MiB
390.60 KiB
3.52 MiB
2.57 MiB
466.04 KiB
139 bytes
37.01 KiB
2.49 MiB

Screen shot

The way I tested. Copy and pasted miskos script to /home/username into a document I made called
used mousepad to go into permissions and make it executable.
Left clicked and tested after plugging in my usb 1st and made sure it automounted it contents.
Closed the file manager window that opens during automount.
Then opened file manager again and left clicked on to run it.
« Last Edit: November 29, 2014, 01:43:30 PM by rokytnji »
LL 3.6,2.8
Dell XT2 > Touchscreen Laptop
Dell 755 > Desktop
Acer 150 > Desktop
I am who I am. Your approval is not needed.

USB drive Storage Summary
« Reply #1 on: November 29, 2014, 03:37:43 AM »


  • Muted
  • Gold Level Poster
  • *
  • 688
  • Reputation: 192
  • Linux Lite Member
    • View Profile

  • CPU: Dual core Pentium E5700 3GHz

  • MEMORY: 3Gb

  • VIDEO CARD: GeForce GT 430
I've been working on this for some time.
This script will calculate USB drive Storage Summary
it's convinient for the USB sticks
It will display what type of files you have on your drive/stick and their size in KB and KiB
Save it anywhere you like, make executable, insert your USB Flash drive or drives and wait until they get auto-mounted.
Then start the script.
Code: [Select]

# store the devices list

# get a list of devices
devs=`ls -al /dev/disk/by-path/*usb*part* 2>/dev/null | awk '{print($11)}'`
if [[ ${?} != 0 || -z ${devs} ]]
    zenity --warning --text "No USB Mounted!"

# Check with user to make sure they mounted usb stick, no use wasting time
zenity --question --title="REMEMBER" --text="Make sure your usb disk is mounted\nDo you want to continue?" --ok-label="Yes" || exit

# Initialize list and make sure it is empty

# Now get the info about our devices and put it in a list
for dev in $devs; do dev="${dev##*\/}";
    echo "FALSE" >> $list;
    echo -n "$dev" >> $list;
    echo " " >> $list;
    echo `cat /sys/block/${dev:0:3}/device/vendor 2>/dev/null` >> $list;
    echo `cat /sys/block/${dev:0:3}/device/model 2>/dev/null` >> $list;
    echo `lsblk 2>/dev/null | grep \`echo -E ${dev}\` |awk '{print($4)}' `B >> $list;
    echo `lsblk 2>/dev/null | grep \`echo -E ${dev}\` |cut -c 38- ` >> $list;
    echo `lsblk -o NAME,FSTYPE 2>/dev/null | grep \`echo -E ${dev}\`| awk '{print($2)}'  ` >> $list;
    echo `ls -l /dev/disk/by-uuid/ 2>/dev/null | grep \`echo -E ${dev}\`| awk '{print($9)}' ` >> $list;

# clear our array

# read in the array using a line tmp variable. This let's zenity see it line by line
while read -r line
done < /tmp/devices

#Display the main dialog
disktmp=$(zenity --list --text="Select your USB drive from the list and click OK to begin.\nThis will calculate what file types you have on the drive and how much space do they consume.\nThe speed of this process depends on the drive size and on the number of files." --radiolist  --width=650 --height=350 --column="Pick" --column="Dev" --column="Vendor" --column="Model" --column="Size" --column="Mount" --column="FS" --column="UUID" "${devfs[@]}" --separator=":")

#Test for cancellation
if [[ ${?} != 0 || -z ${disktmp} ]]
    exit 0

# Extract device

# Start calculating file sizes and convert bytes to human readable
echo "#Please wait, this my take a while"
find "$(echo `lsblk 2>/dev/null | grep \`echo -E ${disk}\` |cut -c 38- `)" -type f -exec file -b '{}' \; -printf '%s\n' | awk -F , 'NR%2 {i=$1} NR%2==0 {a[i]+=$1} END {for (i in a) printf("%12u %s\n",a[i],i)}' | sed -e 's/^[ \t]*//' > ~/usbinform
echo "#Calculating File size"
awk '{print $1}' ~/usbinform | awk '{ sum=$1 ; hum[1024**3]="GiB";hum[1024**2]="MiB";hum[1024]="KiB"; for (x=1024**3; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } if (sum<1024) {printf sum" bytes\n";break } }}' > ~/usbinform1
awk '{print $1}' ~/usbinform | awk '{ sum=$1 ; hum[1000**3]="GB";hum[1000**2]="MB";hum[1000]="KB"; for (x=1000**3; x>=1000; x/=1000){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } if (sum<1000) {printf sum" bytes\n";break } }}' > ~/usbinform2
sed -i 's/\w*.//' ~/usbinform
} | zenity --progress --pulsate --auto-close || exit

# Display results
paste -d'\n' ~/usbinform2 ~/usbinform1 ~/usbinform|zenity --list --title="${disk}" --column="Size" --column="Size KiB" --column="Description" --width=800 --height=650 --ok-label="Save" --cancel-label="OK" --text="Drive ${disk} Storage Summary\n1KB=1000 bytes, 1KiB=1024 bytes"

#Test for cancellation
if [[ ${?} != 0 ]]
    rm ~/usbinform
    rm ~/usbinform1
    rm ~/usbinform2
       exit 0

#Ask where to save our file
zNewData=$(paste -d'\t' ~/usbinform2 ~/usbinform1 ~/usbinform)
zSavePath=$(echo -n "$(zenity --file-selection --save --confirm-overwrite --filename="USBdrive_summary.txt" --title="Save USB drive info")")

#Test for cancellation
f [[ ${?} != 0 ]]
    rm ~/usbinform
    rm ~/usbinform1
    rm ~/usbinform2
       exit 0

echo -n "$zNewData" > "$zSavePath"

# Remove temp files
rm ~/usbinform
rm ~/usbinform1
rm ~/usbinform2


X Close Ad

Linux Lite 7.0 RC1 Released - See Release Announcement Section