-1

Following this issue, I'd love to ask what are the differences between the result of mv files via Terminal, and moving/dragging manually via Finder.

Especially I'd love to know the answer for Mac OS X Ventura, but any other information may be useful

For example, I may think about preserving timestamps, visual location inside the folder (DS_Store), and what else?

P.S. Maybe there's API to perform an "authentic" manual Finder file dragging, but automatically via Terminal? If not in Terminal, maybe in other platform/framework, eg Shortcuts, Workflows, Automator, Xcode?

bmike
  • 235,889
Cocktail
  • 171
  • 1
    What problem are you looking to solve here? Is it looking at the manual pages for mv and then assuming that the filesystem in play is APFS with Ownership enabled? – bmike Nov 16 '22 at 14:11
  • @bmike Basically I want to automate the EXACT specific behavior of moving files via Finder dragging, achieving the same results. I found out that there are some differences I can cover, but I want to be sure I'm not missing something. By the way, by saying automation - I can accept also a "non-code" solution, for example by automating the pointer movements and clicks, if possible, in case there's no other good option, eg API of Finder – Cocktail Nov 16 '22 at 14:14
  • What if Finder does different things than cp? - you may have to reverse engineer things to get that level of detail. There's quite a lot going on with APFS / sparse files, copy on write, shared data on disk - https://eclecticlight.co/2021/07/30/why-nothing-else-can-back-up-to-apfs-like-time-machine-does/ so I was willing to offer an answer if you had something that could be answered in a short post. – bmike Nov 16 '22 at 14:44
  • The biggest benefit to using the mv or the cp commands with files|folders is if you are transferring many thousands or even millions of files|folders. The Finder adds a tremendous amount of processing overhead when faced with extraordinary moving or copying which is mitigated when you use these commands. You can also pipe the result of the mv or cp commands into a log file for future examination to make sure things were moved or copied as expected. – IconDaemon Nov 16 '22 at 14:45
  • 1
    @IconDaemon or use rsync to automatically work around a lot of syncing issues automatically. – nohillside Nov 16 '22 at 14:54
  • @bmike The question about cp is not relevant for me, and of course reverse-engineering is an option, but maybe there's some known information, knowledge, documentation, specifications that allow us to avoid that. For example, in macOS's Shortcuts program, we have the "Move File" command - how to know if I can trust it to be like the Finder's one? – Cocktail Nov 16 '22 at 17:54
  • @IconDaemon Exactly! I just want to know this overhead, what exactly is the difference in terms of results? (I don't care about performance or internal logic) – Cocktail Nov 16 '22 at 17:54
  • Rsync is not relevant for me, as my need is to mimic/automate/describe the operations of Finder's one, not Rsync's one. I want to know what information in filesystem it changes related to the file (but not other files, even related metadata files), what data I will lose if I choose to do mv instead of manual dragging in GUI – Cocktail Nov 16 '22 at 17:57
  • Let's say I want to write my own command-line file moving program, just like mv, but to do it the same way Finder do it behind the scenes. What can I do? – Cocktail Nov 16 '22 at 17:59
  • 2
    Use AppleScript to tell Finder to move the file. – nohillside Nov 16 '22 at 18:43
  • @nohillside Actually I thought your kind suggestion will solve the issue, but as far as I found out, the Apple Script capabilities related to Finder are tied to local machines. But in MV, or RSYNC, you can abstract this level of location, moving files from/to remote servers. Do you have some suggestion? Maybe I miss something about the strength of Apple Script? – Cocktail Nov 27 '22 at 23:46
  • @cocktail what do you mean with remote servers? As long as their volumes are mounted, it makes no difference whether you move files manually in Finder or use AppleScript. – nohillside Nov 28 '22 at 00:06

1 Answers1

0

Since the comments have clarified your goal - I think you don't have an easy "fix". Here's what I can show that the calls are not equivalent for my initial testing on macOS Ventura 13.0.1.

sudo fs_usage | egrep "mv|Finder"

You'll see a lot of Finder chatter and also some non mv related items since my grep is basic. I used uuidgen to dump a UUID to a file named foo and used Finder and mv to move it to my home folder and then back to tmp.

Finder maps the file in memory and uses other file API mv calls traditional seek/rename API. Reverse engineering this is totally possible, but you'd need tools or training and time.

12:16:13  ioctl                                                                                              0.000001   mv          
12:16:13  stat64            private/tmp                                                                      0.000026   mv          
12:16:13  lstat64           /Users/me/foo                                                                    0.000027   mv          
12:16:13  lstat64           /tmp                                                                             0.000010   mv          
12:16:13  stat64            /Users/me/foo                                                                    0.000008   mv          
12:16:13  stat64            private/tmp/foo                                                                  0.000013   mv          
12:16:13  access            private/tmp/foo                                                                  0.000010   mv          
12:16:13  rename            /Users/me/foo                                                                    0.000230   mv          
12:16:13  exit                                                                                               0.000017   mv

compared to

12:16:04  fsgetpath         /private/tmp                                                                     0.000075   Finder      
12:16:04  fsgetpath         /                                                                                0.000057   Finder      
12:16:04  fsgetpath         /private                                                                         0.000018   Finder      
12:16:04  fsgetpath         /private/tmp                                                                     0.000014   Finder      
12:16:04  fsgetpath         /private/tmp                                                                     0.000029   Finder      
12:16:04  fsgetpath         /Users/me                                                                        0.000045   Finder      
12:16:04  fsgetpath         /                                                                                0.000038   Finder      
12:16:04  fsgetpath         /Users                                                                           0.000012   Finder      
12:16:04  fsgetpath         /Users/me                                                                        0.000007   Finder      
12:16:04  fsgetpath         /Users/me                                                                        0.000012   Finder      
12:16:04    WrData[ST2]     me/Library/Saved Application State/com.apple.finder.savedState/window_18.data    0.000434 W Finder      
12:16:04  ftruncate                                                                                          0.000716   Finder      
12:16:04  mmap                                                                                               0.000120   Finder      
12:16:04  PAGE_IN_FILE                                                                                       0.000079   Finder      
12:16:04  fsetxattr                                                                                          0.000168   Finder      
12:16:04  lseek                                                                                              0.000010   Finder      
12:16:04    RdData[SNT2]    rs/me/Library/Saved Application State/com.apple.finder.savedState/data.data.     0.000216 W Finder      
12:16:04  writev                                                                                             0.000435   Finder      
12:16:04  pwrite                                                                                             0.000027   Finder      
12:16:04  ftruncate                                                                                          0.000027   Finder      
12:16:04  ftruncate                                                                                          0.000327   Finder      
12:16:04  mmap                                                                                               0.000107   Finder      
12:16:04  fsetxattr                                                                                          0.000181   Finder      

Whether either of these is fundamentally different once the operation is complete is challenging to generalize (or at least isn't simple to me yet).

bmike
  • 235,889
  • As to the linked thread on dates or timestamps being off, I don't have a repeatable way to trigger that - I wonder if those machines have some other issue going on @cocktail or the OP is looking at other metadata like access time, modified time, etc... – bmike Nov 16 '22 at 18:32
  • what program did you use to track those sys calls? and how did you execute that program? (to say, what Terminal? command you executed and with which arguments). Is it the uuidgen? – Cocktail Nov 16 '22 at 19:37
  • It's sudo fs_usage | egrep "mv|Finder" @Cocktail – bmike Nov 16 '22 at 23:55