Copy Files and directories with su command on rooted device

Opiatefuchs

Similar Questions are often asked here, but I can´t figure out, what exactly I have to do. This is not a duplicate, because the solutions on many threads here are not what I am looking for or doesn´t work for me. I want to copy files and directories to a folder inside the /data/ folder. So, I made a lot of search on SO and Googled for hours. But all the threads I found are not clear enough and don´t let me get what I want. I also found this Blogs, but that doesn´help me.

http://su.chainfire.eu/

http://forum.xda-developers.com/showthread.php?t=1694251

What I have tried

I am able to copy a directory to sd from the /data/ directory without need a su command and it works well just with java code. First question: Is root permission not neccessary for copying from /data/ folder to sd card? The next step I have done is, to execute su command like this:

Process pp  = Runtime.getRuntime().exec("su cat "+originDir+" > "+targetDir);

Where orginDir is the path on sd card from a file and the targetDir is the folder inside the /data/ directory as Strings, for example:

/data/test/testfile.txt

The problem here is, I can copy this file, but it has 0 Bytes. So what I am doing wrong?

What I want

  1. I want to copy a file from sd card to /data/ directory
  2. I want to create a folder on /data/ directory
  3. I want t o copy a whole directory to /data/ directory

I have searched a lot, but I can´t find a good tutorial for using su command to write files to that directory. Also, is there a list anywhere with all in Android available su commands that can be executed programmatically? Belive me, I am not a lazy developer, I have searched many things, but I hadn´t find a good tutorial for this.

Bojan Kseneman

Use ths copy linux command and add -r (recursive) switch to it cp -r /source/ /target/. It will create target if it does not exists

But prior to that you need to make your system is writable

mount -o remount,rw /system 
cp -r /source/ /target/
mount -o remount,ro /system #Don't forget to do this, even if everything else fails!!!!

EDIT: According to comments below, this solution should only be used when targeting relatively new devices

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Copy Files and directories with su command on rooted device

From Dev

Access and manipulate files and directories on an external USB storage in a rooted Android device

From Dev

Android: Can we read file from /data/data/ folder using su command in non rooted device

From Dev

Copy file on change - Rooted android device

From Dev

Linux command that Create and Copy Files and Folder in Multiple directories

From Dev

Linux Command Line - list all directories containing .js files, and copy the directories and their contents to a new folder

From Dev

Is there an ADB command to enable/disable mobile data?(Rooted Device)

From Dev

Copy multiple directories with one command

From Dev

Copy files from few directories

From Dev

Copy files to sub-directories

From Dev

Check if Android device is rooted or not

From Dev

In Windows command prompt, copy one file (or multiple files) to multiple directories that have a user specified name

From Dev

Enumerate files and directories with command 'ls'

From Dev

Copy files and directories without files content

From Dev

Copy files and directories without files content

From Dev

Rooted but su says "Permission denied"

From Dev

Inconsistent access to directories on rooted phone

From Dev

Copy only directories from a command prompt

From Dev

Android ADB stop application command like "force-stop" for non rooted device

From Dev

Using rsync to move (not copy) files between directories?

From Dev

Using rsync to move (not copy) files between directories?

From Dev

How to copy files from multiple directories?

From Dev

How to copy a list files to a list of directories or subdirectories

From Dev

scp to copy all the files without directories

From Dev

copy files from a directory to multiple directories

From Dev

Copy files under list of source directories to target directories using gradle

From Dev

Bash copy files from multiple directories to multiple corresponding backup directories

From Dev

Inverted Screenshot rooted Android device

From Dev

Restricting an application to be installed on a rooted device

Related Related

  1. 1

    Copy Files and directories with su command on rooted device

  2. 2

    Access and manipulate files and directories on an external USB storage in a rooted Android device

  3. 3

    Android: Can we read file from /data/data/ folder using su command in non rooted device

  4. 4

    Copy file on change - Rooted android device

  5. 5

    Linux command that Create and Copy Files and Folder in Multiple directories

  6. 6

    Linux Command Line - list all directories containing .js files, and copy the directories and their contents to a new folder

  7. 7

    Is there an ADB command to enable/disable mobile data?(Rooted Device)

  8. 8

    Copy multiple directories with one command

  9. 9

    Copy files from few directories

  10. 10

    Copy files to sub-directories

  11. 11

    Check if Android device is rooted or not

  12. 12

    In Windows command prompt, copy one file (or multiple files) to multiple directories that have a user specified name

  13. 13

    Enumerate files and directories with command 'ls'

  14. 14

    Copy files and directories without files content

  15. 15

    Copy files and directories without files content

  16. 16

    Rooted but su says "Permission denied"

  17. 17

    Inconsistent access to directories on rooted phone

  18. 18

    Copy only directories from a command prompt

  19. 19

    Android ADB stop application command like "force-stop" for non rooted device

  20. 20

    Using rsync to move (not copy) files between directories?

  21. 21

    Using rsync to move (not copy) files between directories?

  22. 22

    How to copy files from multiple directories?

  23. 23

    How to copy a list files to a list of directories or subdirectories

  24. 24

    scp to copy all the files without directories

  25. 25

    copy files from a directory to multiple directories

  26. 26

    Copy files under list of source directories to target directories using gradle

  27. 27

    Bash copy files from multiple directories to multiple corresponding backup directories

  28. 28

    Inverted Screenshot rooted Android device

  29. 29

    Restricting an application to be installed on a rooted device

HotTag

Archive