I tried using this command:

find /src/dir -type f -exec mv --backup=numbered -t /dst/dir {} +

sourced from here, but error messages suggest find requires root on Android. Any other ideas as to how to accomplish this? I want only the files in the destination folder (i.e. without the directory structure, all files in one directory) while maintaining the source directory structure. I've tried Termux, Terminal Emulator, and Tasker so far, without success.

  • How are you running these commands? adb shell or some third-party terminal app? Dec 20 '17 at 21:29
  • cp -a /src/dir /dst/dir? Guess you want to keep the directory structure, right?
    – Izzy
    Dec 20 '17 at 22:14
  • @TimothyLanger I've tried Termux, Terminal Emulator, and Tasker so far.
    – jdrch
    Dec 21 '17 at 0:34
  • @Izzy No, I don't. I just want the files only in the destination folder while maintaining the source directory structure.
    – jdrch
    Dec 21 '17 at 0:35
  • Ah, that wasn't clear to me (the command used could have been wrong ;) I've integrated that with your question, feel free to edit again if it doesn't fully fit. Strange though that your find claims to require root: I've checked on two devices (LP, MM) and it doesn't. Could you please specify device and Android version? Worth a try: busybox find. If there's no busybox, try toybox. Some variant is running on every device I've seen.
    – Izzy
    Dec 21 '17 at 7:31

OK, after some head-bashing I've realised there's a Linux-specific (Android being based on Linux) mistake being made here - when you type /src/dir the initial / implies that you're looking in the filesystem root, mounted at /. In this case, however, you're probably referring to the current directory, which will likely be in /sdcard/ since you are not rooted. Simply omit the first slash and you're good to go (personally tested).

find src/dir -type f -exec mv --backup=numbered -t dst/dir {} +

If you find still can't perform the function (especially due to an error such as unrecognized option, make sure you install the latest Linux version instead of the one built in to your kernel. This can be done in Termux using pkg install findutils

  • Thanks Timothy. I figured out the solution, which I'll post shortly.
    – jdrch
    Dec 21 '17 at 19:15
  • Hi Timothy, I get unrecognized option for --backup==numbered even after running pkg install findutils and restarting Termux. Ideas?
    – jdrch
    Dec 21 '17 at 19:22
  • Yikes! It worked for me after installing findutils. I have no further ideas since I can't recreate your issue. Sorry! Dec 21 '17 at 20:07
  • I asked at the Github. Looks like it's in coreutils now github.com/termux/termux-packages/issues/…
    – jdrch
    Dec 21 '17 at 23:49

Here's the answer I managed to figure out:

find /SourceDir -type f -exec mv -i {} /DestinationDir ';'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.