So I'm just trying to modify the hosts file on a family members phone. I've put the phone in debug mode and pulled the hosts file, edited it, but when I try to push it I get the message, "adb: error: failed to copy 'D:/hosts\hosts' to '/system/etc/hosts/hosts': remote couldn't create file: Not a directory"
Here's the commands I've used:
adb pull /system/etc/hosts D:\hosts
/system/etc/hosts: 1 file pulled. 0.0 MB/s (56 bytes in 0.003s)
adb push D:\hosts /system/etc/
adb: error: failed to copy 'D:\hosts\hosts' to '/system/etc/hosts/hosts': remote couldn't create file: Not a directory
This is my first time using android debugging/adb and nothing else I've read helped. Thanks in advance.
EDIT: So I've made a little progress. I realized that the hosts file is not in a hosts directory, so I changed it to adb push D:\hosts /system/etc which still didn't work, but adb push D:\hosts\hosts /system/etc gave me the response adb: error: failed to copy 'D:\hosts\hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system So it looks like my problem is now in adb shell chmod
EDIT2: So after some more research I came across this Read only file system on Android. When trying mount -o rw,remount /system I get mount: '/dev/block/dm-0' not user mountable in fstab. In the mounts file /dev/block/dm-0 is on /system. The new problem is fstab is not located in /etc
EDIT3: It looks like my big problem is I have to root the phone I think. I don't have su or sudo to do the remount. Seeing as it's not mine, I don't want to root the phone.
I'm trying to use the Android Adb Command Prompt to copy a folder inside the app container to a local Windows folder. The device is running Android 5.1.1 and is not rooted.
adb pull or cp aren't working. How can I copy a folder?
The following approaches aren't working:
Approach 1
adb shell
adb pull /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs C:/temp/test
error: device not found
Inside the shell you can't see to do adb pull. See here.
Approach 2
DDMS can't access the data folder.
Approach 3
adb shell
run-as DroidSample.DroidSample
cp /files/MetroLog/MetroLogs/ C:/temp/test
cp: /files/MetroLog/MetroLogs/: No such file or directory
Approach 4
adb shell
run-as DroidSample.DroidSample
cp /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs/ C:/temp/test
cp: /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs is a directory (not copied).
This is also not working.
Approach 5
adb shell
run-as DroidSample.DroidSample
chmod 777 /files/MetroLog/MetroLogs
exit
exit
adb pull /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs C:/temp/test
adb shell run-as DroidSample.DroidSample
chmod 700 /files/MetroLog/Metrologs
remote object '/data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs' does not exist
So also this isn't working.
Approach 6
adb shell
mkdir /sdcard/tmp
cp /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs /sdcard/tmp
cp: /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs: Permission denied
This is also not working.
Approach 7
The only thing which half work is this
adb exec-out run-as DroidSample.DroidSample cat "files/MetroLog/MetroLogs/Log - 20160509.log" > C:/temp/test/test.log
But here I don't get the original file and I also have to know the exact file name. Additionally, that I loose line breaks and I have to do this for each file. Not that what I want.
So I'm running out of ideas. How can I access the internal stored files and copy them over?
You have almost solved the problem. As the storage of this kind is secured, you need to do one additional step. You need to copy the file from secured location to sdcard of the device. And then you can copy it anywhere via usb or android pull. Here are the command sequence I executed successfully.
adb shell
run-as DroidSample.DroidSample
cd shared_prefs
cp DroidSample.DroidSample_preferences.xml /sdcard/DroidSample.DroidSample_preferences.xml
exit
exit
adb pull /sdcard/DroidSample.DroidSample_preferences.xml C:/test/
That's it.
And I really appreciate the way you posted your question. Best of luck.
You're trying to gain read access to /data partition on actual android device. Such thing is not possible without root access, even if the app folder is yours. For the reason that permissions to read /data partition are not granted and cannot be granted, unless you're using an emulator. On emulator, which by default is with admin privileges for developer, you can access the data partition to read and write. On actual device you cannot. Not with adb, not with DDMS.
So basically speaking, anything that requires access to those files under /data is not going to work. Whether you sue cp command or pull command. The moment your kernel reads the beginning of your path which starts with /data/... it says: Oops, no can do.
You are trying to access /data folder of android device which is not accessible in unrooted device.
I'm interesting in make some changes in init.rc file.
As I have read, I must get copy of boot.img, unpack it, add my changes to init.rc file, pack and push back new boot.img to phone, and after reboot my changes will be considered. (I can't just change init.rc file, that is at / directory, due to it will be rewritten at next reboot.)
So I try:
adb shell
su
fdisk -l /dev/block/mmcblk0
fdisk outputs list of all partition (mounted and unmounted) which are on phone.
I'm intersting in boot:
9 147456 163839 8192K 0700 BOOT
where 9 - is partition number, so my partition (device to mount) is /dev/block/mmcblk0p9.
Then I remount rootfs to read/write permissions:
mount -o rw,remount rootfs /
Create directory (mount point) /boot:
mkdir /boot
And then try to mount boot partition to /boot:
mount -t auto /dev/block/mmcblk0p9 /boot
but retrive "mount: No such device".
Are anybody faced with this ?
Thanks in advance for you help.
PS:
List of partitions can be also obtained by:
ls -l /dev/block/platform/dw_mmc.0/by-name
Edited:
I have sources, but I don't want to rebuild their, due to a large amount of time compilation. (I must make many changes in init.rc file and recompile all CyanogenMod it's very expensive).
I have tried to build only module tied, as I think, with init.rc (system/core/rootdir), just type mmp:
ila:~/cm_s4/cm_12_1/system/core/rootdir$ mmp
and obtained next line:
Install: /home/ila/cm_s4/cm_12_1/out/target/product/i9500/root/init.rc
but, no line such as (for example, when I type mmp in external/hello_world):
Pushing: /system/bin/hello_world
How to push a file from computer to an Android device having no SD Card in it. I tried:
C:\anand>adb push anand.jpg /data/local
3399 KB/s (111387 bytes in 0.032s)
C:\anand>adb push anand.jpg /data/opt
3199 KB/s (111387 bytes in 0.034s)
C:\anand>adb push anand.jpg /data/tmp
3884 KB/s (111387 bytes in 0.028s)
Above commands to move a file anand.jpg to a device but I didn't get this jpg file in the device.
I didn't get any success result on cmd prompt, I only got:
3399 KB/s (111387 bytes in 0.032s).
From Ubuntu/Mac Terminal, the below command should work.
./adb push '/home/hardik.trivedi/Downloads/one.jpg' '/data/local/'
For adb v33 and above if you are getting a permission denied error, try what I tried. The following command and it works fine.
The only caveat is you might need to use tmp directory on such an emulator.
adb shell //Entering into shell
su //Super user mode
chmod 777 /data/local/tmp/ //Grantint RWX access
exit
chmod 777 /data/local/tmp/ //Grantint RWX access
exit
And then try
./adb push '/home/hardik.trivedi/Downloads/one.jpg' '/data/local/tmp/'
I did it using the push command, which has syntax:
adb push filename.extension /sdcard/0/
Example of copying directory, and sub-directory content:
adb push C:\my-location\data\. /storage/emulated/0/Android/data
Note that push did just hang in latest platform-tools (33.0.1, at time of writing) for a certain amount of files, beside the adb.exe suddenly taking 5MB+ instead of 1.5MB, hence I just did replace the adb.exe with one I had from 28.0.0 version of platform-tools (I did not downgrade the entire platform-tools, because adb.exe is kind of stand-alone).
I don't say there is any conspiracy around data folder,
But my Samsung device puts limits on my USB file transfer, beside Android v11+ not allowing access to data folder anymore, hence I needed above command to work with 100% speed (without hanging one hour for little more files).
Follow these steps :
go to Android Sdk then 'platform-tools' path on your Terminal or Console
(on mac, default path is : /Users/USERNAME/Library/Android/sdk/platform-tools)
To check the SDCards(External and Internal) installed on your device fire these commands :
1) ./adb shell (hit return/enter)
2) cd -(hit return/enter)
now you will see the list of Directories and files from your android device
there you may find /sdcard as well as /storage
3) cd /storage (hit return/enter)
4) ls (hit return/enter)
you may see sdcard0 (generally sdcard0 is internal storage) and sdcard1 (if External SDCard is present)
5) exit (hit return/enter)
to come out of adb shell
6) ./adb push '/Users/SML/Documents/filename.zip'
/storage/sdcard0/path_to_store/ (hit return/enter)
to copy file
Sometimes you need the extension,
adb push file.zip /sdcard/file.zip
run below command firstly
adb root
adb remount
Then execute what you input previously
C:\anand>adb push anand.jpg /data/local
C:\anand>adb push anand.jpg /data/opt
C:\anand>adb push anand.jpg /data/tmp
After Trying all the answers this worked for me
Where I am Pushing a file on Desktop to Android Device (Redmi K20 pro) connected Over the air using adb.
This command pushes the file to the downloads folder on my phone
adb push ~/Desktop/notifications.drawio ./storage/emulated/0/Download
after running this if you get a permission denied error
try running these commands in order (which basically changes the directory permission)
adb shell
chmod 777 /data/local/tmp
exit
and then run try the adb push command
I have documented this here feel free to share your views and help improve it.
Try this to push in Internal storage.
adb push my-file.apk ./storage/emulated/0/
Works in One plus device, without SD card.
My solution (example with a random mp4 video file):
Set a file to device:
adb push /home/myuser/myVideoFile.mp4 /storage/emulated/legacy/
Get a file from device:
adb pull /storage/emulated/legacy/myVideoFile.mp4
For retrieve the path in the code:
String myFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myVideoFile.mp4";
This is all. This solution doesn't give permission problems and it works fine.
Last point: I wanted to change the video metadata information. If you want to write into your device you should change the permission in the AndroidManifest.xml. Add this line:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I've got a Nexus 4, that is without external storage. However Android thinks to have one because it mount a separated partition called "storage", mounted in "/storage/emulated/legacy", so try pushing there: adb push anand.jpg /storage/emulated/legacy
As there are different paths for different versions. Here is a generic solution:
Find the path...
Enter adb shell in command line.
Then ls and Enter.
Now you'll see the files and directories of Android device. Now with combination of ls and cd dirName find the path to the Internal or External storage.
In the root directory, the directories names will be like mnt, sdcard, emulator0, etc
Example: adb push file.txt mnt/sdcard/myDir/Projects/
This might be the best answer you'll may read.
Setup Android Studio
Then just go to view & Open Device Explorer.
Right-click on the folder & just upload a file.
In Mac: To push files via adb
adb push /Users/Downloadsâ©/amazon.sdktester.json '/mnt/sdcard/amazon.sdktester.json'
You are trying to write to system folders. With ADB you have root (admin) access so you see the system folders of which sdcard is one of them so to send a picture you could use
D:\Program Files\Android\sdk\platform-tools\adb push am files\android sdk\adb.exe push C:\Downloads\anand.jpg /sdcard/pictures/
NB: C:\Downloads\anand.jpg replace with path and name to picture..
Certain versions of android do not fire proper tasks for updating the state of file system.
You could trigger an explicit intent for updating the status of the file system.
(I just tested after being in the same OP's situation)
adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///
(You could pass a specific filepath instead of file:/// like file:///sdcard )
In my case, I had an already removed SDCard still registered in Android.
So I longpressed the entry for my old SDCard under:
Settings | Storage & USB
and selected "Forget".
Afterwards a normal
adb push myfile.zip /sdcard/
worked fine.
To push all the files at your directory to the Android device use:
PS D:\myFiles> adb push . '/data/local/tmp/'
My problem is i can write files on sd card in emulator but i find the solution to this problem in stack overflow here to implement that you have to add a group media_rw under android.permission.WRITE_EXTERNAL_STORAGE in platform.xml so for i successfully pulled the xml file but after editing the file i can't push that file so when i am pushing it gives the below error
[Java is awesome]:~$ adb push platform.xml /system/etc/permissions/
failed to copy 'platform.xml' to '/system/etc/permissions//platform.xml': Read-only file system
to overcome this i remount the adb and again i tried i gives the below error
[Java is awesome]:~$ adb remount
remount succeeded
[Java is awesome]:~$ adb push platform.xml /system/etc/permissions/
failed to copy 'platform.xml' to '/system/etc/permissions//platform.xml': Out of memory
so how can push the file or is there any alternative that can enable editing of file with in the adb shell
Thanks in advance
You need to increase the /system partition size accordingly to account for the extra bytes in the file:
You can do this with the following command:
emulator -partition-size <size>
Where is the size depends on your system image plus the extra bytes.