A list of commonly used ADB file commands and how to use them
If you were searching for ADB file commands and wanted to know more about them, you are in the right place. This blog will be throwing light on some of the most used ABD file commands like send, copy, transfer and push. So let’s get started without further ado.
First things first, what is ADB?
Android Debug Bridge (ADB) is a versatile command-line tool that lets you communicate with a device. The ADB command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device. However, you first need to install the ADB package on your computer if it is not already installed. The easiest way to do this is to:
- Install the Android SDK tools if not already installed. You can install it on your Windows by clicking here, on macOS from here and on Linux from here. The rest of the process remains the same for all three.
- Extract the zip folder into an easy-access location such as C://PlatformTools.
- Navigate to the extracted directory and open a command prompt in the same directory as your PlatformTools.
- Next, enable USB debugging on your Android Device from Developer Options. To unlock Developer Options, go to Settings->About Phone and tap seven times on the Build Number.
- Connect your Android device to your PC using a USB cable and open the command prompt in the same directory as your PlatformTools.
- Enter the command adb devices to get the list of your devices.
- You should see your Android device in the output of the above command. This ensures that your device is connected.
Now that you have the ADB installed on your PC, we can move on to learn about the ADB file commands and use them.
#
Command to copy a file
The adb shell cp command is used to copy a file from one directory to another. The general form of this command is adb shell cp /source /destination where “source” defines the directory to copy from and “destination” defines the directory to copy to. It is used for copying files from one location of the Android device to another location. Sometimes, the adb shell cp command ceases to work. This generally happens when you are trying to copy a file that does not exist or copy it to an incorrect destination.
How to use the command:
- Connect your Android device to your PC using a USB cable and open the command prompt in the same directory as your PlatformTools.
- Make sure that USB debugging is enabled on your Android device.
- In the command prompt, run the command adb devices to make sure that your device is connected and recognized.
- Next, run the command adb shell cp /source /destination to copy a file from the source to the destination.
-
Example: adb shell cp /data/local/a/demo.txt /data/local/b/
The above command copies the file “demo.txt” from directory “a” to directory “b”.
- To ensure that the command was successfully executed, navigate to the destination folder using cd and list the contents of the folder. You should see your copied file in it.
Command to push a file
The adb push command is used to copy local files/directories from PC to Android device. The general form of this command is adb push filename.extension /path/to/push/to. Where /path/to/push/to defines the destination location of the Android device. Therefore, the adb push command is a command used for pushing/copying files from PC to Android device. Sometimes, this command might cease to work. This generally happens when you specified an incorrect filename or an incorrect destination to push to.
How to use the command:
- Connect your Android device to your PC using a USB cable and open the command prompt in the same directory as your PlatformTools.
- Make sure that USB debugging is enabled on your Android device.
- In the command prompt, run the command adb devices to make sure that your device is connected and recognized.
- Next, run the command adb push filename.extension /path/to/push/to to push a file from your PC to the destination.
-
Example: adb push pc.apk /mnt/sdcard/Download/test.apk
The above command pushes the file “pc.apk” from the PC to the directory “test.apk” in Android.
- To ensure that the command was successfully executed, navigate to the destination folder using cd and list the contents of the folder. You should see your pushed file in it.
Command to pull a file
The adb pull command is used to copy files and directories from an Android device and save it to your PC. It is the opposite of the adb push command. While the push command pushes a file to the Android device, the pull command pulls a file from the Android device. The general form of the command is adb pull /fileLocation/fileName. The pulled files will be dumped/saved to the same location as your adb.exe on your PC. To save/dump the pulled files to a different location, specify the location while using the pull command like: adb pull /pullLocation/fileName\dumpLocation.
**
How to use the command:**
- Connect your Android device to your PC using a USB cable and open the command prompt in the same directory as your PlatformTools.
- Make sure that USB debugging is enabled on your Android device.
- In the command prompt, run the command adb devices to make sure that your device is connected and recognized.
- Next, run the command adb pull /fileLocation/fileName to pull a file from your Android device and dump it to your PC.
-
Example: adb pull /mnt/sdcard/Download/test.apk
The above command pulls the file “test.apk” from the “Download” directory of the Android device and saves it to your PC.
- To ensure that the command was successfully executed, navigate to the destination folder using cd and list the contents of the folder. You should see your pulled file in it.
Command to transfer/move a file
The adb shell mv command is used to move a file from one directory to another within the Android device. The general form of this command is adb shell mv /fromPath/file /toPath/file. Where “fromPath” defines the path to move from, “file” defines the file to be moved and “toPath” defines the path to move to.
How to use the command:
- Connect your Android device to your PC using a USB cable and open the command prompt in the same directory as your PlatformTools.
- Make sure that USB debugging is enabled on your Android device.
- In the command prompt, run the command adb devices to make sure that your device is connected and recognized.
- Next, run the command adb shell mv /fromPath/file /toPath/file to move a file from one location to another.
-
Example: adb shell mv /mnt/sdcard/Download/test.txt /mnt/sdcard/DCIM/test.txt
The above command moves the file “test.txt” from the “Download” directory of the Android device to the “DCIM” directory of the Android device.
- To ensure that the command was successfully executed, navigate to the destination folder using cd and list the contents of the folder. You should see your moved file in it.
In conclusion, these were four of the most used ABD file commands for pushing, pulling, copying and moving files from one location to another. Hope you try them out.