I have a large (1.3GB) binary file on internal/emulated storage of an Android device running KitKat (4.4.2, API 19); I want to truncate this file to a slightly smaller size (1.2GB), without copying/transferring it all over again.
Device is rooted, and I have adb + shell access.
On Linux I could have just run
truncate --size=1.2G path/to/file
; however the shell pre-installed on the device is BusyBox v1.21.0-jb bionic
, which doesn't seem to contain a built-in truncate
command. Based on [BusyBox changelogs](https://busybox.net/) , truncate
was only added in 1.24.0.
What are my options?
* Device storage has only ~400MB left, so making a dd
-style copy of required size (and then deleting the original) is not an option.
* Could not find an alternative command that would behave in this way (remove trailing content from file / shrink it, in-place).
* Tried copying and running the truncate
binary from another device (Android 8.0); however it wasn't compatible (gave an error CANNOT LINK EXECUTABLE: empty/missing DT_HASH in "./truncate" (built with --hash-style=gnu?)
) (FWIW in the end, found that the binary was actually a toybox
multi-call binary). All other devices at my disposal don't seem to contain truncate
command.
* Tried to find a standalone truncate
binary online - which I can install without touching the existing busybox installation - but could not find any pointers.. or at least any indication that such standalone binaries exist for Android at all
* Tried few common file browsers (device built-in file explorer com.rhmsoft.fm, ES File Explorer) but could not find a suitable action/option.
I would prefer to avoid installing a complete app/apk for this purpose alone, but would go with it if that's the only option; anyways, I'm quite doubtful if such an option would be available in APK form at all.
Asked by Janaka Bandara
(121 rep)
Oct 28, 2022, 02:50 PM