170

In Linux if I want to see all the devices currently connected to my computer in the command-line, I run:

lsblk

or

blkid

The goal here is to be able to obtain information about all storage devices based on its label or other uniquely identifying attributes, even if it hasn't been mounted, thus df is not a viable option.


Examples of the kind of info I'm looking for are:

  • /dev/<dev-name>
  • uuid
  • label (if any)
  • mount point

If possible, I need to be able to see network-attached drives as well.

Is there any equivalent command, program or library that could give the same data for connected storage - both direct and network - under macOS?

0

6 Answers 6

223

diskutil list will list all disks with their identifiers, even if unmounted.

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Mac SSD                 150.0 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4:       Microsoft Basic Data Windows 8               100.1 GB   disk0s4
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *500.1 GB   disk1
   1:                  Apple_HFS George Garside          300.2 GB   disk1s1
   2:               Windows_NTFS GRGARSIDE               199.9 GB   disk1s2

For mounted disks only…

To find the raw device name (i.e. /dev/disk0s1) you can run df.

You can limit the results to locally-mounted filesystems, use df -Hl.
This results in a list of partitions and their raw device names, as shown below:

Filesystem     Size   Used  Avail Capacity  iused    ifree %iused  Mounted on
/dev/disk0s2   150G   130G    20G    87% 31761475  4859615   87%   /
/dev/disk0s4   100G    83G    17G    83%   184667 17015601    1%   /Volumes/Windows 8
/dev/disk1s1   300G   282G    19G    94% 68771109  4529660   94%   /Volumes/George Garside
/dev/disk1s2   200G   172G    27G    87%   144125 26731127    1%   /Volumes/GRGARSIDE
2
  • 1
    Where is the UUID? Commented Aug 31, 2015 at 13:03
  • 1
    Toward helping some users: this command won't do the job if one do the disks has certain corruptions, like btree errors. Then the diskutil will error out before showing the USB device. An impediment when you need to backup to said USB drive before reformatting the corrupt disk Commented Sep 19, 2015 at 18:08
34

Mac OS X offers the system_profiler utility that can be run from Terminal. You can pipe it through grep to find specific strings that you want.

18

Adding this answer to complement aglasser's answer.

If you want to list all the USB Devices connected to your mac, run the built-in app System Information (previously known as System Profiler) in the Terminal app.

List all USB devices:

system_profiler SPUSBDataType

List all PCI devices:

system_profiler SPPCIDataType

See also:

2

From at least High Sierra 10.13.6 you can use the system profiler (About This Mac > System Report > SATA/SATA Express) to give you a list of all mounted SATA devices and get the UUID of each mounted Disk by name. If you have unmounted drives use Disk Utility to mount them.

2
  • 4
    Don‘t think this will work from the command line
    – nohillside
    Commented May 18, 2020 at 19:28
  • 1
    diskutil (or hdiutil) can mount a disk (or rather, its partitions), but only the partitions which are each formatted as a file system known to macos. You can find the known file systems with diskutil listFilesystems. Commented May 5, 2021 at 20:40
2

Updated steps for macos ventura: to see the UUID of attached drives (including the Apple SDXC card reader):

  • click the apple menu () -> About this mac -> More Info
  • in the System Settings: General window scroll down and click System Report
  • Under Hardware -> Storage for each device you'll see something like Volume UUID: 64BC182A-CA9D-4AA1-8936-D2919863C22A
1

The goal here is to be able to obtain information about a device based on its label or other uniquely identifying attributes, even if it hasn't been mounted, thus df is not a viable option.

If that is your goal, then you can obtain all of that info from a specified disk using diskutil info /dev/diskX where diskX is the disk that you want to obtain information about.

NOTE: In your goal, you did not say that you wanted to obtain all information about all disks all at once in one command. So I am not answering that question, as your originaly question seems different than your stated goal. You may want to make some edits to specify what you are trying to accomplish and how.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .