You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Verify and Repair Disk Permissions via Terminal (Mac OS X)
Verify Permissions
diskutil verifyPermissions /
Repair Permissions
diskutil repairPermissions /
Verify and Repair Volume via Terminal (Mac OS X)
Launch Terminal from your Dock, Utilities folder, or via an app launcher like Alfred. Once launched, type or paste in the following command.
diskutil verifyVolume [drive name]
So, for your main hard drive, you could type or paste in something like:
diskutil verifyVolume /
Or, if you have an external drive attached, you can type or paste in the following:
diskutil verifyvolume /Volumes/[drive name]/
So for an external drive named “BackupStuff” you would enter:
diskutil verifyvolume /Volumes/BackupStuff/
If you see no messages, then you can assume that diskutil hasn’t found any errors, and you can move on. If, however, you get an error like “The volume Macintosh HD was found corrupt and needs to be repaired,” then you can repair the drive using diskutil as well.
To repair the drive, you can issue the following command into Terminal:
You can try booting from OS X recovery by holding CMD + R at the time of startup. Once booted from OS X recovery, select Terminal from the utilities and then at the unix prompt enter:
diskutil list
then press return and look for the disk identifier and enter the following command with the disk identifier:
sudo diskutil unmountDisk /dev/(enter here disk identifier name)
Press return and enter your admin password if prompted. This should unmount all volumes of the physical drive.
If still the above method didn't work, then the last option is to force the entire disk to unmount.
For that using the terminal application again, enter the following command:
sudo diskutil unmount force /dev/(enter here disk identifier name)
Then press return and enter the admin password if prompted. This will definetely unmount the entire disk and all its related volume.
Time Machine is a great tool for ensuring that your data is safe, and it's pretty easy to set up and use. But for some users, the basic Time Machine interface isn't enough. As with most of OS X's functions, there is a command-line tool that lets you do many things with Time Machine. Here's how you can use the tmutil command to control and tweak Time Machine from Apple's command-line tool, Terminal.
The basics
Most people won't need to use this command for their backups because the Time Machine interface will suffice. Who will need it? People who want to manage remote Macs or who want to run scripts containing commands for Time Machine.
The basics of the tmutil command can be found by typing man tmutil in Terminal. (You'll find the Terminal app in your /Applications/Utilities folder.) The man page tells you what you can do with this command.
For example, to turn Time Machine on or off, you can run these commands:
sudo tmutil enable
sudo tmutil disable
The sudo command is required for many of the commands you issue with tmutil because you need administrative privileges; you'll have to enter your password after running the above commands.
If you want to run a Time Machine backup right away, on a Mac that either has Time Machine disabled, or, say, just before updating to a new version of OS X, you can run this command:
tmutil startbackup
This is the same as choosing Back Up Now from the Time Machine menu in the menu bar at the top of your screen.
And if you ever want to stop a backup, just run this:
tmutil stopbackup
Save disk space on your laptop
Since your laptop isn't always connected to its backup disk, Time Machine retains "local snapshots," or files that it will copy to your backup disk the next time it is available. However, these local snapshots take up space, and you may want to turn this feature off if you don't have much room on your hard disk. You can do so with the following command:
sudo tmutil disablelocal
Running this command will also delete any local snapshots. You can turn local snapshots back on by running:
sudo tmutil enablelocal
If you love delving into the nitty-gritty, and especially if you manage remote Macs, you'll find this to be a very useful tool.
Exclude files and folders
You can exclude certain files and folders from your Time Machine backups from the Time Machine pane in System Preferences. Naturally, you can also do this from the command line, too. Run this command:
sudo tmutil addexclusion
The part stands for the path to a file or folder. For example, if I want to exclude my Downloads folder from Time Machine backups, I would run the following:
sudo tmutil addexclusion ~/Downloads
The tmutil addexclusion command has an interesting property: it's sticky. When you use this command, the item you exclude remains in the Time Machine exclusion list even if you move it, which is not the case when you exclude items from the Time Machine preference pane. If you use the above command with the -p flag, then it will not be sticky, and will be the same as an exclusion you add from the Time Machine preference pane.
Manage remote backups
If you're managing a remote Mac, such as a server, you may want to change Time Machine settings for that computer. You can start by finding where Time Machine backups are stored. Run this command:
tmutil destinationinfo
You'll see something like this in Terminal:
Name : TM Backup
Kind : Local
Mount Point : /Volumes/TM Backup
ID : B9DAT9A6-0C37-4C39-A2AE-10A3403C97F9
To change the destination, you can use two commands. First, remove the current destination like this:
tmutil removedestination
In place of , type in the text string returned by the destinationinfo command. Then run this command to set up a new destination disk:
tmutil setdestination _volume_name_
Replace _volume_name_ with the name of the disk or volume you want to use. You can add multiple destinations as well, since Time Machine can rotate its backups on several disks or volumes. See man tmutil for more on setting up multiple backup destinations. (You can now do this without the command line too, see "How to create redundant Time Machine backups.")
Get Time Machine stats
Time Machine saves a lot of backups: one per hour for the past 24 hours; one a day for the past week; and one a week before that. You can get a list of all the backups on your Time Machine disk with this command:
tmutil listbackups
This will show the full path of each backup.
If you're curious about how much has changed in your Time Machine backups, there's a command that will let you find out how much of each backup is new. Run this command to see the delta between each of the Time Machine backups on your backup disk or volume:
tmutil calculatedrift _backup_folder_
Replace _backup_folder_ with the path of the folder containing your backups. This is not the Backups.backupdb folder at the top level of your Time Machine volume, but rather the next folder down; this is generally labeled with your Mac's name.
For example, when I ran this command on my backups, I saw data like this:
Here's what I saw when I ran the tmutil calculatedrift backup_folder command on my Mac.
Note that this command takes a long time to run, as your Mac has to calculate a lot of information.
The tmutil command offers many other options, such as the ability to inherit destinations, perform detailed comparisons of backups, restore items and much more. See man tmutil to find out all that you can do.
If you love delving into the nitty-gritty, and especially if you manage remote Macs, you'll find this to be a very useful tool.
in 10.13: repairpermissions doesnt work with diskutil...
appleRAID <verb> (Perform additional verbs related to AppleRAID)
coreStorage <verb> (Perform additional verbs related to CoreStorage)
apfs <verb> (Perform additional verbs related to APFS)
diskutil with no options will provide help on that verb
sh-3.2# diskutil coreStorage
Usage: diskutil [quiet] coreStorage|CS
where is as follows:
list (Show status of CoreStorage volumes)
info[rmation] (Get CoreStorage information by UUID or disk)
convert (Convert a volume into a CoreStorage volume)
revert (Revert a CoreStorage volume to its native type)
create (Create a new CoreStorage logical volume group)
delete (Delete a CoreStorage logical volume group)
rename (Rename a CoreStorage logical volume group)
createVolume (Create a new CoreStorage logical volume)
deleteVolume (Delete a volume from a logical volume group)
encryptVolume (Start encrypting a CoreStorage logical volume)
decryptVolume (Start decrypting a CoreStorage logical volume)
unlockVolume (Attach/mount a locked CoreStorage logical volume)
changeVolumePassphrase (Change a CoreStorage logical volume's passphrase)
resizeVolume (Resize a CoreStorage volume)
resizeDisk (Resize a CoreStorage physical volume disk)
resizeStack (Resize a CoreStorage logical/physical volume set)
diskutil coreStorage with no options will provide help on that verb
in coreStorage it seems the most logical for Apple itself... But on all apples I removed corestorage because it becaue unreliable on the long run. I was happy to have a backup of 3 TB to an outside WD 4TB ;-)
sh-3.2# diskutil appleRAID
Usage: diskutil [quiet] appleRAID|AR
where is as follows:
list (Display the current status of RAID sets)
create (Create a RAID set on multiple disks)
delete (Delete an existing RAID set)
repairMirror (Repair a damaged RAID mirror set)
add (Add a spare or member disk to an existing RAID)
remove (Remove a spare or member disk from an existing RAID)
enable (Convert a volume into a single disk RAID set)
update (Update the settings of an existing RAID)
This one might contain the old command:
sh-3.2# diskutil apfs
Usage: diskutil [quiet] ap[fs]
where is as follows:
list (Show status of all current APFS Containers)
listUsers (List cryptographic users/keys of an APFS Volume)
listSnapshots (List APFS Snapshots in a mounted APFS Volume)
convert (Nondestructively convert from HFS to APFS)
create (Create a new APFS Container with one APFS Volume)
createContainer (Create a new empty APFS Container)
deleteContainer (Delete an APFS Container and reformat disks to HFS)
resizeContainer (Resize an APFS Container and its disk space usage)
addVolume (Export a new APFS Volume from an APFS Container)
deleteVolume (Remove an APFS Volume from its APFS Container)
eraseVolume (Erase contents of, but keep, an APFS Volume)
changeVolumeRole (Change the Role metadata bits of an APFS Volume)
unlockVolume (Unlock an encrypted APFS Volume which is locked)
lockVolume (Lock an encrypted APFS Volume (diskutil unmount))
changePassphrase (Change the passphrase of a cryptographic user)
setPassphraseHint (Set or clear passphrase hint of a cryptographic user)
encryptVolume (Enable FileVault security in background or instantly)
decryptVolume (Disable FileVault security in background or instantly)
deleteSnapshot (Remove an APFS Snapshot from an APFS Volume)
updatePreboot (Update the APFS Volume's related APFS Preboot Volume)
Muchas Gracias por la información y sus comentarios ya que estoy pasando unos momentos muy difíciles con mí disco duro y 4 scurity cards realmente desde Apple desde que cambió la arquitectura, densidad y 3xtructura del disco al formato APFS que parece que los discos bueno mis drivers se derritieron o se hicieron chiclosos tenía varios comandos en mente ya que soy un usuario muy viejo de las Apple como desde los 80 s teníamos unas lisas pero bueno divago.
Recordé que año pasado estaba encriptado mí disco llevaba 2 días encriptado hubo una lluvia muy fuerte que no hubo luz así que imaginarán que se acabó la batería al 83 % del progreso tarde 6 días en ayar la solución Ya que Sierra había incluido diskutilty " cs " d8sk error restore bach format.
Disculpen por escribir en español pero estoy con poco tiempo solo 4 gigas tengo para reparar. Gracias por tan valiosa información y colaboración, compañeros. Hace a nice note !!!
I keep getting a error on my MacBook pro that an error has occurred while preparing installation.....I'm tryin to install is x el Capitan .........HELP PLEASE
Very nice summary.
I have a serious problem with an external disk. It was my TimeMachine, and it will no longer mount. Does anyone know how to fix it, or where I could get help?
Here is output when running: sudo fsck_hfs -fryd /dev/disk5
journal_replay(/dev/disk5) returned 0
** /dev/rdisk5
Using cacheBlockSize=32K cacheTotalBlock=65536 cacheSize=2097152K.
Executing fsck_hfs (version hfs-522.0.9).
** Checking Journaled HFS Plus volume.
The volume name is Seagate
** Checking extents overflow file.
Invalid leaf record count
(It should be 190 instead of 192)
** Checking catalog file.
** Rebuilding catalog B-tree.
hfs_UNswap_BTNode: invalid node height (1)
** The volume Seagate could not be repaired.
volume type is pure HFS+
primary MDB is at block 0 0x00
alternate MDB is at block 0 0x00
primary VHB is at block 2 0x02
alternate VHB is at block 15626665982 0x3a36bfffe
sector size = 512 0x200
VolumeObject flags = 0x07
total sectors for volume = 15626665984 0x3a36c0000
total sectors for embedded volume = 0 0x00
CheckHFS returned 8, fsmodified = 1
Very nice summary.
I have a serious problem with an external disk. It was my TimeMachine, and it will no longer mount. Does anyone know how to fix it, or where I could get help?
Here is output when running: sudo fsck_hfs -fryd /dev/disk5
journal_replay(/dev/disk5) returned 0
** /dev/rdisk5
Using cacheBlockSize=32K cacheTotalBlock=65536 cacheSize=2097152K.
Executing fsck_hfs (version hfs-522.0.9).
** Checking Journaled HFS Plus volume.
The volume name is Seagate
** Checking extents overflow file.
Invalid leaf record count
(It should be 190 instead of 192)
** Checking catalog file.
** Rebuilding catalog B-tree.
hfs_UNswap_BTNode: invalid node height (1)
** The volume Seagate could not be repaired.
volume type is pure HFS+
primary MDB is at block 0 0x00
alternate MDB is at block 0 0x00
primary VHB is at block 2 0x02
alternate VHB is at block 15626665982 0x3a36bfffe
sector size = 512 0x200
VolumeObject flags = 0x07
total sectors for volume = 15626665984 0x3a36c0000
total sectors for embedded volume = 0 0x00
CheckHFS returned 8, fsmodified = 1
If you still are grappling with this issue have you tried using testdisk to repair your drive after cloning it?
silanukprach@MacMini ~ % sudo fsck_hfs -fryd / dev / disk5
Password:
/ is not a character device
CONTINUE? yes
** / (NO WRITE)
Can't get device block size
dev: No such file or directory
Can't stat dev
Can't stat dev: No such file or directory
/ is not a character device
CONTINUE? yes
** / (NO WRITE)
Can't get device block size
disk5: No such file or directory
Can't stat disk5
Can't stat disk5: No such file or directory
silanukprach@MacMini ~ %
A good guide, indeed.
A few simple comments - a partition on my iMac would not boot up. A grey screen appeared instead, with the prohibitory symbol (circle with a line through it). I decided to erase & reformat the partition, but Disk Utility could not unmount it. I followed the directions above to unmount the partition using Terminal.
First, diskutil list gave me its name (iMac20), but sudo diskutil unmount force /dev/iMac20 would not unmount it.
Out of curiosity, I then ran diskutil verifyvolume /Volumes/iMac20 to verify and repair the disk. Normally, Disk Utility would have to unmount the partition before verifying it. But Terminal didn't bother; it successfully verified the partition even though it previously could not unmount it. I then tried to unmount iMac20 again in Terminal, with no success.
Then I noticed a previous line in Terminal, where the partition had been given another name: Finished file system verification on disk0s8 iMac20
Using the alternative name (disk0s8), I tried unmounting it again: sudo diskutil unmount force /dev/disk0s8
This time it worked: I could then mount & unmount it in Disk Utility, as well as erase it.
I don't know if this name thing has any significance, but it seemed to work.
(For others as ignorant as I – when a disk's name is highlighted in the left column of Disk Utility, its disk number appears at the bottom of the window.)
Exactly what i needed. thanks. Thanks to this thread and https://www.handyrecovery.com/fix-corrupted-hard-drive-on-a-mac/ was able to figure out repair external hard drive mac terminal issue. Took me couple of days but absolutely worth it. Next time i will have solutions ready for a similar problems
Thanks a lot for the help! I finally figured out that to fix corrupted hard drive mac isn’t as complicated as I initially thought. After some research, I came across this article that outlines the entire process: https://www.cleverfiles.com/howto/fix-corrupted-hard-drive-mac.html. It breaks everything down into simple, easy-to-follow steps and covers a range of solutions depending on the severity of the issue. If you’re dealing with a similar problem, I highly recommend checking it out. It helped me a lot in getting my drive back up and running without losing any data
According to man diskutil (dated 7 October 2015),
"Starting with Mac OS X 10.11, the verify- and repairPermissions verbs have been removed."