I'm trying to use arduino-cli to upload a pre-compiled and exported .hex file to a Nano connected via USB to an old Raspberry Pi (with 256mb RAM, relatively slow IO, etc). My sketch is about 50K when compiled.
Running arduino-cli upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano -i mysketch.ino.eightanaloginputs.hex takes a good few minutes, consumes around 100MB of RAM and on my very resource-constrained system, sometimes fails altogether.
I went in search of something "better". I appreciate this is a bit specific to my setup, and so other chip and board types may need to do something different, but this works in a fraction of the time, with a fraction of the resources:
To get the .hex file, I'm writing the code on my laptop in the Arduino IDE (with the board type set to "Nano", as that's what I'm using) and clicking Sketch->Export Compiled Binary. It's creating the file mysketch.ino.eightanaloginputs.hex in the project folder, which I'm then SCPing over to the Raspberry Pi to upload to the Arduino. If you're just starting out on the Pi, then you'll need to run sudo apt install avrdude to get the avrdude program.
The same technique can be extended to other setups. The overhead from the arduino-cli upload command is because Arduino CLI dynamically generates the necessary upload command, which requires it to process all your installed boards platforms and tools so that it can assemble the command from the information they provide.
We can take advantage of that automagical generation of the upload command provided by Arduino CLI. If you do a single upload via Arduino CLI and add the --verbose flag to the arduino-cli upload (or arduino-cli compile --upload) command, you will see the upload command Arduino CLI generated for the specific board, port, and sketch specified via the . You can then simply copy and paste that command and run it directly thereafter.
Neat tip, @ptillisch - taking that a step further, I just realised that if you go to Preferences in the IDE, you can enable "Show verbose output during... upload". You get a lot of extra chatter in the bottom activity box of the IDE, but in there will be the avrdude command line to upload your sketch to the device.
(This has just proven handy when trying to set fuses in an attiny being programmed by a Duemilanove ;-))