Skip to content

Terminal

The macOS’ version of the cp Unix command won’t create links

I ran into this while working on a Keyboard Maestro macro that creates hard links: The macOS version of cp won't create links, at least not in Sonoma. In Ventura, it works even though it throws the same error as it does in Sonoma.

Copying as hard links is part of the cp feature set, fully covered in its man pages. But it doesn't work in macOS. To confirm, try this:

When I ran into this, I searched and discovered that someone else had run into the same issue,1Apple Developer login required but that's the only mention I could find.

I have filed this bug as FB13255408 with Apple, and I'm hopeful they fix it soon. There is a workaround, obviously: Use ln instead. This works fine for individual hard links, but using cp to quickly copy an entire folder as hard links is a nicer implementation.



More helpful help for Terminal commands

I use Terminal a fair bit, for any number of things. But I don't use it all the time, and that means I sometimes struggle to remember syntax of commands. "Was it rsync source destination or the other way around? Or was it ln that was backwards of what I thought it should be?"

You can open the man page for a command, of course, but sometimes there's so much there that finding the simple thing you want is tough. Enter tldr, installable via Homebrew or MacPorts. tldr skips most of the detail of the man pages, providing user-curated examples of how to use a given command.

As an example, here's the aforementioned rysnc command's man page:

[continue reading…]





VMware Fusion and the vmmon broken pipe error

As part of my struggles to fix my constantly-crashing suggestd process (and the Spotlight failures that it seems to cause), I reinstalled macOS Mojave a couple of times using the Internet Recovery partition. These were in-place reinstalls, so I didn't start completely clean, but the OS is reinstalled from scratch—so much so that I even had to run the 10.14.6 updater and a couple of security updates again.

In the end, not only did this not fix the suggestd problem, but it also broke my all-important VMware Fusion virtual machines. When I tried to launch any of them, I was greeted with an error message:

Error: Could not open /dev/vmmon: Broken pipe

This is apparently so common that VMware has a knowledge base article on the issue. The error is due to VMware Fusion not loading its required kernel extensions, but nobody seems to be sure of the cause of the problem. However, that article is supposed to fix it…unfortunately for me, it did not. I never saw an entry in the Security & Privacy System Preferences panel to allow VMWare's extensions. As a result, they didn't load.

Here's the tl;dr for the fix that did work: Rebooting in Recovery mode (hold down Command-R at startup) and deleting the KernelExtensionManagement folder located in /private/var/db. There was a lot more to it than that, though, which I cover for my own possible future needs in the rest of this post, in case the linked sources ever vanish.

[continue reading…]



See dot files at top of ls output in Linux

In Terminal on macOS, the ls (list directory contents) command sorts the output of its "all files" listing so that hidden files (those that begin with a dot) appear at the top of the list, like this:

$ ls -Alh
total 47640
-rw-r--r--@   1 robg  staff    28K Oct 26 15:00 .DS_Store
drwxrwxrwx@   5 robg  staff   160B Oct 23  2016 .TemporaryItems
... [trimmed for display]
drwxr-xr-x    8 robg  staff   256B Sep 19 08:31 .wine
drwx------   13 robg  staff   416B Apr 13  2019 Applications
drwx------+  20 robg  staff   640B Oct 26 12:36 Desktop
... [trimmed for display]

On the server that hosts my personal sites (as well as Many Tricks), however, ls doesn't sort the invisible files to the top:
[continue reading…]



Go old school Terminal for stock quotes

My main machine is still running Mojave, and will be for some time—our accounting app and my scanner both rely on 32-bit code. For a very long time, I've been using the built-in Stocks widget from the Dashboard (something else that's gone in 10.15) to track stocks I own or am interested in following.

I have two displays, so I just dedicate a small corner on one of them for the Dashboard widget, which I detach from the Dashboard using an old but still functional Dashboard devmode hint. The Stocks Dashboard widget is quite narrow, and not all that tall, so it didn't take a lot of space.

But recently, it broke, as you can see in the image at right. I set out looking for a replacement—just a simple desktop app that would open a window with stock quotes. Apple's own Stocks app doesn't meet my needs—it has a huge News area you can't close. Similarly, the Stocks section of the Today area in Notification Center requires mouse movement and action on my part to see.

I took a look at any number of third-party apps, but all of them were either full-blown stock traders/managers, lived in the menu bar or Dock, or were discontinued. I finally found what I was looking for, not in a desktop application, but in mop—an open source Go program—running in Terminal.

After a bit of setup work, here's what I'm now seeing1While I wish I had bought a lot of these years ago, I didn't—these are just some sample stocks on my desktop:

Yes, the window is slightly wider than my old one2It's actually incredibly wide, but I don't need to see the other columns, but it's not as tall, and I was able to find a spot for it. If you'd like to try mop yourself, setup is relatively simple.

[continue reading…]



How to upgrade a web host’s command-line PHP

The following is a very geeky, very niche1Where 'niche' is defined as 'of interest to maybe one person' tip, and I'm only documenting it here because it took me a while to figure it out, and I'd like to not have to go through that again if the need arises.

This site, and a few other personal projects, are hosted at Ionos, with whom I've been generally happy. On the web/GUI side, Ionos makes it really easy to control which version of PHP is used on your sites.

But I also have command line access to my server there, and I ran into an issue trying to run a PHP script (to upgrade another site). It threw an error, so I thought I'd check which version of PHP was in use…

$ which php
/usr/bin/php
$ /usr/bin/php --version
PHP 4.4.9 (cgi-fcgi) (built: Aug 29 2019 12:59:15)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

PHP 4.4.9 was discontinued in 2008—no wonder the script threw an error!

[continue reading…]



Living the bifurcated life in macOS Catalina

If you're a macOS Catalina user, and a user of Terminal for various tasks, you might be surprised at how some things work—or rather, don't work, in Catalina. As a first example, consider the Utilities folder…on the left is how it appears in Finder, and on the right, the contents of that same folder listed in Terminal:

While Finder shows a full Utilities folder, Terminal shows it as empty. Why? If you're somewhat familiar with the technical side of macOS Catalina, you probably know the answer: Apple has separated much of the OS and placed it on a read-only volume.

Apple's "About the read-only system volume in macOS Catalina" page explains things fairly well—basically, what you see as one Utilities folder in Finder is really two things: A read-only Utilities folder, and a user-writable Utilities folder. (If my machine had any user-installed apps in the Utilities folder, they would have shown up in the Terminal output above.)

[continue reading…]



See exactly when an app launched

Update: I guess I should have searched here before I posted this—I wrote up another solution a few years ago, and that one includes a Keyboard Maestro implementation. Whoops! As this one's another method, though, I'll leave it up.

I was working on some stuff for our upcoming Usher 2 release, and needed to know how long Usher had been running. A quick web search found this post, where one of the comments had an answer that works well in macOS:

ps -p pid -o lstart=

Replace pid with the process ID (PID) from ps -ax for the app or process in question, and you're done. But it's possible to make it even easier to use by automating the task of getting the process ID. Here's what I came up with:

ps -p `ps ax | grep [U]sher$ | cut -c 1-5` -o lstart=

The bit between the backticks gets the matching process line from ps, then uses cut to keep just the first five columns, which contain the PID.1When the shell encounters backticks, it processes the commands within those backticks before processing the rest of the command—in this case, the backticked command returns the PID.

[continue reading…]



Quickly create a nested folder structure via Terminal

Have you ever needed to create an empty folder structure with many levels of repetitively-named folders? This doesn't happen a lot, obviously, but if you try using Finder for this task, you'll quickly discover it's really tedious. But a quick trip to Terminal makes the task very fast, and it's not overly complicated.

Let's say you need a folder structure to handle reports that you'll be receiving weekly, but need to keep track of over both quarters and years. One way to handle that would be with a folder structure like this:

(Hopefully obviously, the same structure repeats within each separate year's folder.) Creating that many multi-leveled folders in Finder would be time consuming and tedious. But in Terminal, you can create the entire structure with just one command:

mkdir -p 202{0..5}/qtr{1..4}/week{1..13}

That command takes under a second on my iMac to create the entire directory structure (over 330 folders). Zoom! So how does this work?

[continue reading…]