DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Mounted Volumes On Mac OS X

  • submit to reddit
        // description of your code here

# See also:
# localvols in

/bin/df -l | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+)[^\/]+//' | /usr/bin/sort -u
/bin/df -l | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+){5}//' | /usr/bin/sort -u

/bin/df -a | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+)[^\/]+//' | /usr/bin/sort -u

declare IFS=$'\n'
#for volume in $(/bin/df -l | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+)[^\/]+//' | /usr/bin/sort -u); do 
for volume in $(/bin/df -a | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+)[^\/]+//' | /usr/bin/sort -u); do 
   echo "vol: $volume"
declare IFS=$' \t\n'

# Cf. Get A List Of Mounted USB Drives

system_profiler SPUSBDataType | grep "BSD Name:" | awk '{gsub (" BSD Name: ","");print}'
diskutil info disk1
diskutil info disk1s3

system_profiler SPUSBDataType | sed -E -n 's/ *BSD Name: *([^ ]*)/\1/p'

declare IFS=$'\n'
for device in $(system_profiler SPUSBDataType | sed -E -n 's/ *BSD Name: *([^ ]*)/\1/p'); do
   for usbdevice in $(diskutil info "$device" | sed -E -n 's/ *Mount Point: *(.*)/\1/p' | sed '/^ *$/d'); do
      echo "USB device mounted at: ${usbdevice}"
declare IFS=$' \t\n'