Ask Different (Apple)
Q&A for power users of Apple hardware and software
Latest Questions
5
votes
1
answers
124
views
MacOSX shell directory utilities very slow with large directories (millions of files) - any alternatives?
Due to a problem with contact synchronization (not sure what was the source of the problem, probably a program crash on powercut, which caused inconsistency in contact's database file), the synchronization process created nearly 7M files in `Images/`: ``` hostname:Images username$ pwd /Users/usernam...
Due to a problem with contact synchronization (not sure what was the source of the problem, probably a program crash on powercut, which caused inconsistency in contact's database file), the synchronization process created nearly 7M files in
Images/
:
hostname:Images username$ pwd
/Users/username/Library/Application Support/AddressBook/Sources/4D81D34B-C932-4578-8A31-4E2E244B3875/Images
hostname:Images username$ ls
^C
hostname:Images username$ ls | wc -l
6797073
(the result was after hours)
hostname:Images username$ cd ..
hostname:4D81D34B-C932-4578-8A31-4E2E244B3875 username$ ls -l
total 600224
-rw-r--r--@ 1 username staff 409600 Aug 2 17:43 AddressBook-v22.abcddb
-rw-r--r--@ 1 username staff 32768 Aug 3 00:13 AddressBook-v22.abcddb-shm
-rw-r--r--@ 1 username staff 2727472 Aug 2 23:26 AddressBook-v22.abcddb-wal
drwx------ 65535 username staff 231100550 Aug 2 23:26 Images
-rw-r--r--@ 1 username staff 45056 Dec 7 2017 MailRecents-v4.abcdmr
-rw-r--r--@ 1 username staff 32768 Dec 7 2017 MailRecents-v4.abcdmr-shm
-rw-r--r--@ 1 username staff 4152 Dec 7 2017 MailRecents-v4.abcdmr-wal
drwx------ 5 username staff 170 Feb 26 18:51 Metadata
-rwxr-xr-x 1 username staff 0 Dec 7 2017 OfflineDeletedItems.plist.lockfile
-rwxr-xr-x 1 username staff 0 Dec 7 2017 Sync.lockfile
-rwxr-xr-x 1 username staff 0 Dec 7 2017 SyncOperations.plist.lockfile
When I tried to use shell tools (ls
, find
), I did not get any result in time reasonable for interactive work (it was hours), regardless of disabling file sorting like ls -f
(what [seems to help in case of other UNIX-like OSs](https://unix.stackexchange.com/questions/120077/the-ls-command-is-not-working-for-a-directory-with-a-huge-number-of-files)) etc.
The ls
process has grown to around 1GB in size and worked for HOURS before outputting any result.
My question is - am I missing some tricky option to have this working reasonably for large directories (outputting the results on the way, eg. to process further, filter etc.) or these tools are just not written to scale? Or maybe there are better file/directory utilities for MacOSX? (I haven't tried any GUI app on that directory, thinking better not to...).
I have written a fairly trivial C program reading the directory entries and outputting the info on the way:
#include
#include
#include
#include
#include
#include
#include
int main( const int argc,
const char * const * argv )
{
const char * const dirpath = argv[ 1 ];
DIR * const dirp = opendir( dirpath );
if ( dirp == NULL )
return -1;
int count = 0;
struct stat statbuf;
for ( struct dirent * entry = readdir( dirp );
entry != NULL;
entry = readdir( dirp ), count++ )
{
char filepath[ PATH_MAX + 1 ];
memset( filepath, 0, PATH_MAX );
strncat( filepath, dirpath, PATH_MAX );
strncat( filepath, "/", PATH_MAX );
strncat( filepath, entry->d_name, PATH_MAX );
stat( filepath, &statbuf );
printf( "%s %llu\n", entry->d_name, statbuf.st_size );
}
closedir( dirp );
printf( "%d", count );
return 0;
}
which actually does work (outputs the result after reading each entry) and has memory footprint of around 300K. So it is not a problem of the OS (filesystem, driver, standard library or whatever), but the tools which basically do not scale well (I know they support more options etc., but for a basic directory listing, without sorting or anything fancy ls
should work better, ie. not allocate 1GB of memory, while find
should do the action for each entry it finds (and matches), not read them all first, as it apparently does...).
Has anyone experienced this and has a good solution how to deal with such huge directories (what utilities to use) on MacOSX? (Or maybe writing some custom system utility is necessary in such case?)
(It is an exceptional situation of course, occurred for the first time on my system - but the OS supports such large directories, and the basic shell tools should deal with them in a _reasonable_ way...)
EDIT:
Small fix in the program (the filepath was lacking '/').
t-w
(101 rep)
Aug 3, 2021, 12:23 PM
• Last activity: Jun 23, 2025, 11:55 AM
0
votes
1
answers
191
views
MANPATH, 'whereis' and how manuals are located?
I use a 2023 M2 MBP running Ventura 13.7.2. To augment Apple's rather paltry offerings of CL utilities, I depend on MacPorts. Unfortunately, MacPorts does not have a replacement/alternative for `whereis`. If you've ever used Apple's native `whereis` you may have noticed that it has some ***shortcomi...
I use a 2023 M2 MBP running Ventura 13.7.2. To augment Apple's rather paltry offerings of CL utilities, I depend on MacPorts. Unfortunately, MacPorts does not have a replacement/alternative for
whereis
.
If you've ever used Apple's native whereis
you may have noticed that it has some ***shortcomings***; e.g.:
/usr/bin/whereis find
find: /usr/bin/find /opt/local/libexec/gnubin/man/man1/find.1.gz
First - it only reports on native apps**See EDIT 1 below**. Its **app** searches are restricted by Apple, and apparently this cannot be over-ridden by any user.
Second - as you can see above, it has no such restrictions on searching for manuals. In this case, it reports on the manual location for the find
tool which was installed from MacPorts.
Third - the native whereis
found the manpage for find
without benefit of the MANPATH
environment variable - it is not set on my system.
Fourth - AFAIK, that leaves only manpath
(another Apple-sourced CL utility) as a resource for finding the location of manuals. However, **as I read** man manpath
- it's not getting it from there either!
So that's my question: How does Apple's whereis
command find the location of system manuals? Have I mis-read man manpath
? Can someone explain the process?
Also, I'd be interested to know if Apple publishes the source files for manpath
and whereis
.
---
#### EDIT 1: "What is meant by native apps?"
From man whereis
on my system (dated "August 22, 2002, for macOS 13.7"):
>The default path searched is the string returned by the sysctl(8) utility for the “user.cs_path” string, with /usr/libexec and the current user's $PATH appended.
On my system:
% sysctl user.cs_path
user.cs_path: /usr/bin:/bin:/usr/sbin:/sbin
WRT ***"... Its app searches are restricted by Apple, and apparently this cannot be over-ridden by any user."***: You may refer to [this post](https://github.com/seamusdemora/seamusdemora.github.io/blob/master/MacStuff.md#39-whereis-vs-which-and-why-Apple-sucks) which was based on some research I did a while ago. Referring to man sysctl
on my current mac, is the following:
>COMPATIBILITY
The -w option has been deprecated and is silently ignored.
Seamus
(5329 rep)
Feb 3, 2025, 07:12 AM
• Last activity: Feb 4, 2025, 08:22 AM
26
votes
12
answers
12255
views
Snap feature for Mac?
Coming from Windows I have gotten extremely used to the Windows Snap feature, which resizes a window when it's dragged to the screen edges. However, it's not built into OS X. Are there any 3rd party utilities that add this functionality?
Coming from Windows I have gotten extremely used to the Windows Snap feature, which resizes a window when it's dragged to the screen edges.
However, it's not built into OS X. Are there any 3rd party utilities that add this functionality?
Jacob
(363 rep)
Mar 2, 2011, 09:15 PM
• Last activity: Sep 28, 2024, 02:28 PM
1
votes
1
answers
261
views
Why are there two Utilities folders in my Applications folder?
MacOs Ventura 13.6.1, I don't recall seeing two Utilities folders before. In fact I thought it was impossible to have identically-named files (or folders) in the same location (Applications in this case). What's going on? [![enter image description here][1]][1] [1]: https://i.sstatic.net/hp9oV.png
MacOs Ventura 13.6.1, I don't recall seeing two Utilities folders before. In fact I thought it was impossible to have identically-named files (or folders) in the same location (Applications in this case).
What's going on?

frogola
(253 rep)
Nov 3, 2023, 09:04 PM
• Last activity: Aug 1, 2024, 07:01 PM
277
votes
7
answers
212160
views
How to replace Mac OS X utilities with GNU core utilities?
I found there is some differences between the utility command I used on the mac OSX and linux. I want to make my experience united. How could I replace all my mac utilities with GNU utilities?
I found there is some differences between the utility command I used on the mac OSX and linux. I want to make my experience united.
How could I replace all my mac utilities with GNU utilities?
steveyang
(2935 rep)
Oct 22, 2012, 02:49 PM
• Last activity: Jul 7, 2024, 09:40 AM
365
votes
40
answers
228097
views
What Window Management Options exist for OS X?
I'd like to do **something** with my windows on OS X, where **something** includes options like re-arranging, moving, re-sizing, remembering positions, cloning across Spaces, etc. What options exist? ### Rules - **One** app per answer. - Use this format for the first two lines of your answer: **`##...
I'd like to do **something** with my windows on OS X, where **something** includes options like re-arranging, moving, re-sizing, remembering positions, cloning across Spaces, etc. What options exist?
### Rules
- **One** app per answer.
- Use this format for the first two lines of your answer:
**
## [app name](link to website)
**
**[App Store](link to appstore) (price)
**
- **Check for duplicates** before adding new answers.
- If you find a duplicate, vote it down and encourage its poster to upvote the original entry instead (and remove the dupe).
- Include short **description** about what this Window Managing app does.
- What makes this Window Manager app different than the others?
- Is it focused on re-sizing using only the keyboard?
- Is it focused on moving using only mouse gestures?
- Etc.
user588
Mar 5, 2011, 06:01 PM
• Last activity: May 22, 2024, 05:29 PM
3
votes
1
answers
85
views
ES Explorer is using over 50GB: how can I empty it without reinstalling it?
ES Explorer is using over 50GB on my iPhone 12 mini (~57.7GB): [![enter image description here][1]][1] I don't see anything in ES Explorer: [![enter image description here][2]][2] How can I empty it without reinstalling it? [1]: https://i.sstatic.net/SxBXZ.png [2]: https://i.sstatic.net/4UM7F.png
ES Explorer is using over 50GB on my iPhone 12 mini (~57.7GB):
I don't see anything in ES Explorer:
How can I empty it without reinstalling it?


Franck Dernoncourt
(3616 rep)
Apr 9, 2024, 04:03 PM
• Last activity: May 3, 2024, 02:00 PM
0
votes
1
answers
447
views
xattr: bad interpreter: No such file or directory
When I execute the `xattr` command, it returns the error: ```` /usr/local/bin/xattr: /usr/local/opt/python@3.11/bin/python3.11: bad interpreter: No such file or directory ```` `file /usr/bin/xattr` returns: ```` /usr/bin/xattr: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit exec...
When I execute the
xattr
command, it returns the error:
`
/usr/local/bin/xattr: /usr/local/opt/python@3.11/bin/python3.11: bad interpreter: No such file or directory
`
file /usr/bin/xattr
returns:
`
/usr/bin/xattr: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/usr/bin/xattr (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/xattr (for architecture arm64e): Mach-O 64-bit executable arm64e
`
which python3
returns /usr/bin/python3
and my env
doesn't have any python entries.
This is my .zshrc
file:
`
export PATH="/usr/local/sbin:$PATH"
export PATH="/usr/local/sbin:$PATH"
# Created by pipx
on 2023-11-25 17:42:38
export PATH="$PATH:/Users/rhpt/.local/bin"
`
I do not have python 3.11 but I do have python 3.12 installed. Running Sonoma 14.2 on an Intel iMac.
I do not understand why xattr
is trying to execute a python script. How can I get Terminal to use the executable instead of trying to execute python?
RHPT
(788 rep)
Jan 18, 2024, 05:44 AM
• Last activity: Jan 18, 2024, 09:08 AM
5
votes
1
answers
1872
views
How do I see what applications or services are preventing an external flash drive from ejecting?
I know there are general solutions out there to deal with problems ejecting hard drives, but I'd like to get more specific and understand what applications are causing problems so that I can deal with them without closing *every* app or by logging out when I'm in the middle of working. Or worse stil...
I know there are general solutions out there to deal with problems ejecting hard drives, but I'd like to get more specific and understand what applications are causing problems so that I can deal with them without closing *every* app or by logging out when I'm in the middle of working. Or worse still to be unable to reformat an external disk or to do disk operations like create a bootable installer which is what prompted me to ask this question.
Looking in the Activity Monitor > Disk Tab didn't seem to be very helpful. I'd have to go by a hunch and check the info for an app, look at Open Files and Ports tab, scan the Open Files for directories that match the problematic disk and or volume. This process is needlessly tedious. There's got to be a better way.
I'd like to be able to use an Application or a Terminal command, point to the disk or volume in question and have it return what Applications are preventing the disk from ejecting.
Are there software or utilities that specialize in preventing applications from needlessly molesting external drives? I would consider a well written script/service. I don't mind using command line utilities to get the job done.
I was considering downloading Little Flocker again and seeing if I could apply it to my external drives. Every application would be blocked from accessing my external drives until I aprove it or make a rule via Little Flocker. But apparently Little Flocker was bought out by F-Secure :(.
For what it's worth I'm on MacOS Sierra V. 10.12.5
adamlogan
(468 rep)
May 23, 2017, 10:47 AM
• Last activity: Nov 10, 2023, 11:05 AM
8
votes
8
answers
39476
views
What is the quickest Mac OS X app to use to remove the background of an image to make it transparent?
I followed the instructions in [How to use Preview for Basic Image Editing: Remove Backgrounds and Extract Shapes][1] to use the Preview app to remove backgrounds with an image. The problem is that the "Instant Alpha" tool sometimes does not capture all the pixels and can't figure out how to use the...
I followed the instructions in How to use Preview for Basic Image Editing: Remove Backgrounds and Extract Shapes to use the Preview app to remove backgrounds with an image. The problem is that the "Instant Alpha" tool sometimes does not capture all the pixels and can't figure out how to use the rectangle tool to remove those remaining pixels. I tried highlighting the pixels and then pressing delete but it doesn't work. Can someone explain how to do it or recommend another free, lightweight Mac OS X tool to remove background to make it transparent? I do not want to use Photoshop or anything else expensive.
Chirag Patel
(691 rep)
May 14, 2011, 07:09 PM
• Last activity: Sep 28, 2023, 09:48 PM
2
votes
1
answers
199
views
Estimate "true" APFS disk usage of folder without counting cloned files multiple times
I would like to compute how much "true" APFS disk space is used by a folder. This folder has many APFS "cloned" versions of the same files. A "true" count of the disk space used would only count each of these clones once. One thought I've had is to do this: 1. Go through each file in the folder, rec...
I would like to compute how much "true" APFS disk space is used by a folder. This folder has many APFS "cloned" versions of the same files. A "true" count of the disk space used would only count each of these clones once.
One thought I've had is to do this:
1. Go through each file in the folder, recursively.
2. Somehow determine, for each file, which physical location on the drive that file maps to.
3. Build an array of these locations for all files; prune duplicates when they appear (which would be clones).
4. Get the total computed size.
I am curious if one could use this kind of method to get the true size of the folder. I'm also curious if there are any existing utilities to do this, or if not, how I could implement this on my own. Perhaps using
fcntl
and F_LOG2PHYS
, from [this answer](https://stackoverflow.com/a/65241088/2762570) ?
Mike Battaglia
(181 rep)
Jul 23, 2023, 04:30 PM
• Last activity: Aug 22, 2023, 09:03 PM
0
votes
0
answers
628
views
How to bypass password authentication when booting into macOS Recovery
I have an Apple Silicon machine with FileVault enabled, and when I boot into macOS Recovery, it asks for a password before letting me use the utilities etc. I have forgotten my password, so I cannot get past this initial password recovery app screen, but I need to use the integrated utilities. I wan...
I have an Apple Silicon machine with FileVault enabled, and when I boot into macOS Recovery, it asks for a password before letting me use the utilities etc.
I have forgotten my password, so I cannot get past this initial password recovery app screen, but I need to use the integrated utilities.
I want to install macOS on a separate partition without erasing the existing installation and my data.
I have not found anything for a situation like this online.
*If somebody has an idea of how I can skip the password recovery utility and get to the macOS install tool, please help.*
**Additional info:**
I do know what the password could be, but I entered it incorrectly and now when I boot into the normal OS, it does not even try to check whether my password is incorrect or not. I do not know why this is since I did not use all 10 attempts before the password or the recovery key can only be entered in the Recovery OS for another 10 attempts each. (According to the apple support page regarding password logins)
I know that the Mac has stopped processing my password attempts in the normal OS because the password field immediately shakes after pressing enter without any delay at all and because I can try as many different combinations as I want without the message "Wait - minutes before next try".
I lost the recovery key. So I can't log in normally.
yehaaaw
(1 rep)
Jun 13, 2023, 12:30 AM
• Last activity: Jun 13, 2023, 02:28 AM
2
votes
2
answers
6486
views
How do I trigger a script when a second monitor is attached
I am on macOS El Captain (upgrading to High Sierra soon) and I'm looking for a tool which can trigger an AppleScript or shell script every time when the number of monitors/displays attached to the system changes. I have tried [*ControlPlane*](https://www.controlplaneapp.com/), but could not get the...
I am on macOS El Captain (upgrading to High Sierra soon) and I'm looking for a tool which can trigger an AppleScript or shell script every time when the number of monitors/displays attached to the system changes.
I have tried [*ControlPlane*](https://www.controlplaneapp.com/) , but could not get the trigger on attached-display-change to work. Two questions:
1) Does anybody know that display triggering in *ControlPlane* definitely works on macOS El Captain and higher? (Indicating that I am doing something wrong.)
Or:
2) Is there another tool which can act on a change of numbers of displays every time a monitor/display is (dis-)connected?
***
**PS**: I am aware there are other questions in the StackExchange network relating to this topic (like [How can I run a script whenever I plug in an external monitor?](https://superuser.com/questions/170545/how-can-i-run-a-script-whenever-i-plug-in-an-external-monitor) or [Reset Mac OS X Windows Position after de-attaching external monitor](https://superuser.com/questions/331/reset-mac-os-x-windows-position-after-de-attaching-external-monitor)) , but the answers do not seem to apply to El Captain/High Sierra .
halloleo
(1497 rep)
Aug 13, 2018, 04:42 AM
• Last activity: Apr 26, 2023, 02:20 AM
15
votes
4
answers
14794
views
Why is 'xattr' not working?
When I attempt to execute `xattr` in Terminal, I get Traceback (most recent call last): File "/usr/bin/xattr-2.7", line 33, in import xattr ImportError: No module named xattr What's going on here? I thought xattr [was part of Darwin][1]. Is `xattr` written in Python? Does it require a Python package...
When I attempt to execute
xattr
in Terminal, I get
Traceback (most recent call last):
File "/usr/bin/xattr-2.7", line 33, in
import xattr
ImportError: No module named xattr
What's going on here? I thought xattr was part of Darwin . Is xattr
written in Python? Does it require a Python package to be installed on my system?
orome
(12163 rep)
Mar 29, 2014, 12:34 AM
• Last activity: Feb 13, 2023, 10:15 AM
4
votes
2
answers
3007
views
What built-in utilities are available in macOS for managing/monitoring process/disk/memory/IO/file?
I think Activity Monitor can be used for managing/monitoring processes, but I am confused about the other four: disk/memory/IO/file. Are all these four functions be managed/monitored out by Disk Utility?
I think Activity Monitor can be used for managing/monitoring processes, but I am confused about the other four: disk/memory/IO/file.
Are all these four functions be managed/monitored out by Disk Utility?
charlesw
(43 rep)
Apr 23, 2021, 03:03 AM
• Last activity: Nov 30, 2022, 05:14 AM
7
votes
1
answers
1397
views
Colorsync Utility calculator picks colors only from Desktop background
I'm trying to use ColorSync Utility calculator on macOS Big Sur 11.6.5. And it doesn't work. I cannot pick a correct color. The color picker looks through any application windows disregarding them and picks only colors of the respective areas on the Desktop background behind those windows. The only...
I'm trying to use ColorSync Utility calculator on macOS Big Sur 11.6.5. And it doesn't work. I cannot pick a correct color. The color picker looks through any application windows disregarding them and picks only colors of the respective areas on the Desktop background behind those windows. The only app window which works is ColorSync Utility itself. How do I fix it and make it work?
Andrey Chernukha
(231 rep)
Aug 8, 2022, 10:09 AM
• Last activity: Nov 10, 2022, 07:33 PM
12
votes
4
answers
9968
views
What programs exist to find and delete "orphan files" left after deleting an Application?
I have transferred my system from Mac to Mac for over 15 years. I have preference files and other plists lurking around in my system for programs I tested years ago. Is there a smart program that could point me to these orphan files knowing that the application that created them is not on my system?
I have transferred my system from Mac to Mac for over 15 years. I have preference files and other plists lurking around in my system for programs I tested years ago.
Is there a smart program that could point me to these orphan files knowing that the application that created them is not on my system?
Barth
(503 rep)
Sep 7, 2012, 06:53 AM
• Last activity: Oct 16, 2022, 11:35 PM
25
votes
10
answers
163683
views
Is there a file copy utility for OS X that's similar to TeraCopy for Windows?
On Windows, I use [TeraCopy](http://www.codesector.com/teracopy.php) for improved file copying. Are there any similar equivalents for OS X? In particular, I'd like to see things like copy speed.
On Windows, I use [TeraCopy](http://www.codesector.com/teracopy.php) for improved file copying. Are there any similar equivalents for OS X?
In particular, I'd like to see things like copy speed.
Ian
(649 rep)
Nov 28, 2010, 06:43 PM
• Last activity: Oct 6, 2022, 10:38 AM
3
votes
3
answers
385
views
Is there a keyboard shortcut to organize or align two finder windows?
I know that there were some 3rd party apps that could do this in the past, but with each new version of Mac OS X, it seems that many of those 3rd party apps stop working or the project ages and loses it's maintainer. I'm wondering if there is a Mac OS X built-in keyboard shortcut to do this. I suppo...
I know that there were some 3rd party apps that could do this in the past, but with each new version of Mac OS X, it seems that many of those 3rd party apps stop working or the project ages and loses it's maintainer.
I'm wondering if there is a Mac OS X built-in keyboard shortcut to do this. I suppose this wouldn't be limited to finder windows, but for windows of any application.
David Killingsworth
(155 rep)
Jul 12, 2018, 05:27 PM
• Last activity: Oct 3, 2022, 08:56 AM
3
votes
3
answers
38944
views
Can’t choose startup disk after wiping hard drive from OSX Utilities
I’m helping someone with their old laptop (17”, mid-2009, if that matters). I restarted with cmd R to load OSX Utilities, and I used Disk Utility to wipe Macintosh HD, overwriting it three times and formatted as OS X Extended (Journaled). Afterwards, after successfully connecting to my Wi-Fi, I clic...
I’m helping someone with their old laptop (17”, mid-2009, if that matters). I restarted with cmdR to load OSX Utilities, and I used Disk Utility to wipe Macintosh HD, overwriting it three times and formatted as OS X Extended (Journaled).
Afterwards, after successfully connecting to my Wi-Fi, I clicked on Reinstall OS X, and it’s giving me the option to set up El Capitan (the OS X that’s installed, and from what I can tell, the latest that can be installed). But when I hit continue, it gives me an error message:
> An error occurred while preparing the installation. Try running this application again.
I get the same message every time I try. So I thought I’d try quitting OS X Utilities without reinstalling OS X and see what happens.
After clicking on Choose Startup Disk, I get a blank list to choose from, with a restart button. No startup disks are available. Clicking restart, as one might expect, yields the following error message:
> **You can’t change the startup disk to the selected disk.**
>
>Startup Disk could not gather enough information on the selected disk.
So I quit Startup Disk and went back to Disk Utility, and I tried running First Aid on both Macintosh HD and OS X Base System. Neither one had any issues.
So what is my issue? Did I mess up when wiping the hard drive? Do I just need to reformat it? Is there anything I can do, or have I rendered this computer a hunk of junk? Also, how do I prevent this in the future?
DonielF
(1092 rep)
Mar 27, 2018, 05:45 PM
• Last activity: Jul 5, 2022, 07:44 AM
Showing page 1 of 20 total questions