2012-05-26 09:09:09 +0000 2012-05-26 09:09:09 +0000
61
61
Advertisement

如何在OSX上获取USB设备的挂载路径?

Advertisement

我有一个备份脚本,将一些数据备份到USB设备上。我的问题是OSX有时会改变预期的挂载路径。例如,如果某些文件被锁定在预期的挂载路径下,OSX就会将其挂载到另一个路径上。一个名为 “BACKUP "的USB设备可以挂载在/Volumes/BACKUP-1而不是/Volumes/BACKUP。

有没有办法在OSX终端中找出USB设备的当前挂载路径?类似于'mount\_path BACKUP'(命令是假的),然后返回’/Volumes/BACKUP-1',或者如果设备没有被挂载,则什么也不返回?

Advertisement
Advertisement

答案 (8)

72
72
72
2012-05-26 09:56:13 +0000

以下命令显示了关于挂载卷的信息。

  • 著名的Unix mount,显示例如安装在0x6的/dev/disk5s3
  • /Volumes/Foo显示所有磁盘和卷的概况
  • diskutil list显示该卷的信息,包括可以用来唯一标识该卷的diskutil info /dev/disk5s3

您可以使用卷的UUID查询Volume UUID

$ diskutil info DEC8759E-F77D-3EAE-B3EB-B6438F1AA428 | grep 'Mount Point'
   Mount Point: /Volumes/DroboOne
  • *

我的系统上的命令输出示例。

$ mount
/dev/disk1 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
localhost:/bNqIvVr1ZdFBdf19Io81Q4 on /Volumes/MobileBackups (mtmfs, nosuid, read-only, nobrowse)
/dev/disk4 on /Volumes/MyBook (hfs, local, nodev, nosuid, journaled)
/dev/disk5s3 on /Volumes/DroboOne (hfs, local, nodev, nosuid, journaled, noowners)
/dev/disk7s3 on /Volumes/DroboTwo (hfs, local, nodev, nosuid, journaled, noowners)
/dev/disk6s3 on /Volumes/DroboThree (hfs, local, nodev, nosuid, journaled, noowners)

$ diskutil list
/dev/disk0
   #: TYPE NAME SIZE IDENTIFIER
   0: GUID_partition_scheme *256.1 GB disk0
   1: EFI 209.7 MB disk0s1
   2: Apple_CoreStorage 240.0 GB disk0s2
   3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1
   #: TYPE NAME SIZE IDENTIFIER
   0: Apple_HFS Servus10 HD *239.7 GB disk1
/dev/disk2
   #: TYPE NAME SIZE IDENTIFIER
   0: GUID_partition_scheme *3.0 TB disk2
   1: EFI 209.7 MB disk2s1
   2: Apple_CoreStorage 3.0 TB disk2s2
   3: Apple_Boot Boot OS X 134.2 MB disk2s3
/dev/disk4
   #: TYPE NAME SIZE IDENTIFIER
   0: Apple_HFS MyBook *3.0 TB disk4
/dev/disk5
   #: TYPE NAME SIZE IDENTIFIER
   0: Apple_partition_scheme *2.2 TB disk5
   1: Apple_partition_map 32.3 KB disk5s1
   2: Apple_HFS DroboOne 2.2 TB disk5s3
/dev/disk6
   #: TYPE NAME SIZE IDENTIFIER
   0: Apple_partition_scheme *2.2 TB disk6
   1: Apple_partition_map 32.3 KB disk6s1
   2: Apple_HFS DroboThree 2.2 TB disk6s3
/dev/disk7
   #: TYPE NAME SIZE IDENTIFIER
   0: Apple_partition_scheme *2.2 TB disk7
   1: Apple_partition_map 32.3 KB disk7s1
   2: Apple_HFS DroboTwo 2.2 TB disk7s3

$ diskutil info /dev/disk5s3
   Device Identifier: disk5s3
   Device Node: /dev/disk5s3
   Part of Whole: disk5
   Device / Media Name: Untitled

   Volume Name: DroboOne
   Escaped with Unicode: DroboOne

   Mounted: Yes
   Mount Point: /Volumes/DroboOne
   Escaped with Unicode: /Volumes/DroboOne

   File System Personality: Journaled HFS+
   Type (Bundle): hfs
   Name (User Visible): Mac OS Extended (Journaled)
   Journal: Journal size 172032 KB at offset 0x4001000
   Owners: Disabled

   Partition Type: Apple_HFS
   OS Can Be Installed: No
   Media Type: Generic
   Protocol: FireWire
   SMART Status: Not Supported
   Volume UUID: DEC8759E-F77D-3EAE-B3EB-B6438F1AA428

   Total Size: 2.2 TB (2198888927232 Bytes) (exactly 4294704936 512-Byte-Blocks)
   Volume Free Space: 169.4 GB (169412173824 Bytes) (exactly 330883152 512-Byte-Blocks)
   Device Block Size: 512 Bytes

   Read-Only Media: No
   Read-Only Volume: No
   Ejectable: Yes

   Whole: No
   Internal: No
```。
10
10
10
2012-10-26 20:32:46 +0000

这个命令怎么样?

df -lH | grep "Filesystem"; df -lH | grep "/Volumes/*"

在 “Mounted on "一栏中,你可以得到所有安装在"/Volumes"上的设备的所有挂载点,在我的情况下,几乎都是USB设备;-)

grep命令基本上跳过了安装在"/"上的硬盘。

在我的OSX Snow Leopard终端中,我用它来快速浏览当前连接的USB设备的挂载点。如果你只对挂载点感兴趣,而不是对UUID等其他参数感兴趣,在我看来,这是比"diskutil"及其所有信息更直接的方法。

2
Advertisement
2
2
2015-12-29 11:14:55 +0000
Advertisement

我把它检索到一个变量中。

media=我把它检索到一个变量中。

df | grep "media" | awk '{print $6}'我把它检索到一个变量中。


或者

media=$(df | awk '/media/ {print $6}')

df命令列出了分区,输出的结果被管道化,作为grep命令的输入,grep命令只过滤并保留包含media这个词的行,然后再被管道化到awk命令,该命令只保留一行输入的第6列。

1
1
1
2019-05-11 12:18:33 +0000

只是好的老diskutil。这不是Linux,在那里你可能会偷看到/sys什么的。

diskutil info "$VolumeName" | grep "Mount Point" | tr " " "\n" | tail -1
0
Advertisement
0
0
2015-02-25 15:53:57 +0000
Advertisement

这是我在OS X上的shell脚本中使用的内容

df | awk '{print $6}' | grep -Ex "/Volumes/myvolume"
```。
0
0
0
2012-05-26 12:33:15 +0000

我只想用fstab来解决这个问题。在超级用户上有一个关于这个话题的帖子: Mac Lion: fstab已经过时了,那么用什么代替它来防止分区挂载呢?

0
Advertisement
0
0
2012-09-26 09:25:39 +0000
Advertisement

我最终使用了这个bash脚本:

#!/bin/sh
#
# Retrieves the mount point of an OSX volume name or UUID.
# @param $1 Name of the volume or UUID of the volume.
# @return returns the mount path or an empty string if the volume is not mounted. 
#
diskutil info $1 | grep 'Mount Point' | cut -d : -f 2 | sed 's/^ *//g' | sed 's/ *$//g';
```。
-1
-1
-1
2017-04-27 13:40:38 +0000

这可能更好。

df -lH | grep -E "*putinyourvolumelabel*$" | awk '{print $1}''
Advertisement

相关问题

12
11
6
5
1
Advertisement
Advertisement