5

Every once in a while I find that I need to use the -rl options of cp to clone a directory tree using hardlinks. This has always worked fine on Linux, and I can see that the BSD cp command accepts the same options. When I try to link a file on macOS, I get:

cp -l  release-source/release/examples/stubs-1-pubsub.test.js .
cp: ./stubs-1-pubsub.test.js: Bad file descriptor

This made it seem like the copying failed, but ls shows it went fine:

ls -li  release-source/release/examples/stubs-1-pubsub.test.js stubs-1-pubsub.test.js
9825657 -rw-r--r--  2 carlerik  staff  1072 26 sep 16:24 release-source/release/examples/stubs-1-pubsub.test.js
9825657 -rw-r--r--  2 carlerik  staff  1072 26 sep 16:24 stubs-1-pubsub.test.js

So ... what is going on?

System information

❯ npx envinfo --system

  System:
    OS: macOS 13.5.2
    CPU: (12) arm64 Apple M2 Max
    Memory: 4.24 GB / 64.00 GB
    Shell: 5.2.15 - /opt/homebrew/bin/bash

❯ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 TB     disk0
   1:             Apple_APFS_ISC Container disk1         524.3 MB   disk0s1
   2:                 Apple_APFS Container disk3         2.0 TB     disk0s2
   3:        Apple_APFS_Recovery Container disk2         5.4 GB     disk0s3
5
  • Did you ever find an answer? I'm on macOS Sonoma and I used to use the command cp -al dirA dirB on earlier OSes, but it doesn't seem to work anymore, giving the same error Bad file descriptor
    – deecypher
    Oct 13, 2023 at 17:07
  • On the Apple forum a developer said that's a bug I need to report. Works anyway 😸
    – oligofren
    Oct 14, 2023 at 6:13
  • @oligofren what do you mean by saying "works anyway?"
    – Oion Akif
    Nov 27, 2023 at 20:50
  • @OionAkif Did you read the above? I write that nothing seems functionally wrong from inspection, yet I do get an error message.
    – oligofren
    Dec 2, 2023 at 10:17
  • Until this is fixed, you can install the coreutils package with homebrew and use gcp in place of `cp.
    – Turn
    Feb 27 at 0:12

1 Answer 1

2

This has been submitted as bug to Apple: FB13434700

You must log in to answer this question.

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