Using adb To Copy Files To / From Your Android Device

Some devices, like the Galaxy Nexus and the HP Touchpad* (via the custom Android ROMs) don’t expose themselves as USB storage devices.  They instead use MTP or PTP to transfer media files (limiting to only photos and audio/video files being shown from the device).

This happens due to there being no separate sdcard on these devices, and ‘unplugging’ an sdcard from a running device to be exposed to the connected computer could cause running apps on the device itself to malfunction.  Android developer Dan Morill explains this here. He also mentions how the Nexus S doesn’t have this problem.

There are several apps that can open shares to the device using one of several protocols (DAV, SMB, etc.).  However, one quick way I’ve found to copy files to and from the device connected via USB to a computer is by using the adb tool.  It’s available as part of the ‘android-tools’ package on Fedora.

To copy a file from the computer to an android device connected via usb, use this:

adb push /path/to/local/file /mnt/sdcard/path/to/file

This will copy the local file to the device in the specified location.  Directories can be created on the device via the shell:

adb shell

and using the usual shell commands to navigate around and create directories.

* On the Touchpad, WebOS can expose the storage as a USB Storage Media.  The current nightly builds of CM9 can’t.

16 Replies to “Using adb To Copy Files To / From Your Android Device”

  1. Did not know that, although I’ve recently coded a bit with eclipse which, I guess, uses the adb-shell in the building process. I guess the shell has some advantages to root apps running on the device but, at least on windows (wonder if it’s available on linux), autocompletition of filenames, editing or viewing files with ‘vi’, ‘nano’ or ‘less’ isn’t build into the shell. So you have to copy the file to a local harddisc with ‘adb pull /sdcard/foo.txt D:\bar.txt’, edit it in Notepad++ and put it back on the device with ‘adb push D:\bar.txt /sdcard/’. I think I’ll write a gui for that. Will post the link if that’s ok?

    1. if you have the android sdk for linux it will be in the files. Android-sdk.r22.3-linux.tgz from androids’ web sight you have it in your platform tools folder. ADB in shell is a linux terminal into it will remote shell right into the device if you wanted to pull somefile to local home or location where adb is its

      “adb pull /foldername/foldername/filename foldernametobecopiedto”

      adb push copies from location to device location.

      now if you are like me you will just place adb with your other term commands and well done but if you do be mindful that you give exact file path or you will have to get it from where adb is.

  2. Hi, I came to your post and found useful. Let me describe a problem I am having. My tablet does not load. I managed to recover apps via adb. However, I don’t manage to have access to sdcard: it seems to be empty. Idon’t think it is actually blank. Rather I feel the problem has to do with the issues you highlight. Can you think of any strategy to have access to my documents in sdcard. You mention several packages but I am not familiarized with the topic. Thanks

  3. I want to move a rom which i backed up and it is in sdcard/clockworkmod/restore

    i want to move it to sdcard/clockworkmod/backup

    my phone is LG L3 E400. rooted.
    Have access to cwm.
    Thats all

  4. I want to send a font and boot animation my tab is not working after boot it does booting only any suggestions. I hv installed clockwork mod. Please anyone there who knows how to start my phone please email me.

  5. Do you know where the deleted data gets stored in android? I am not able to root the device, so only way now is if I can copy the data via adb. However I don’t know where deleted data gets stored

  6. Hi
    How to create an ANT script to push files from local machine to an android attached device
    I am using Android Studio
    And tell me whether i can write ANT script to automate build process or do we have any other way by using Gradle
    Please help me out with this as I am new to Android


Leave a Reply

Your email address will not be published. Required fields are marked *