Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove file on android using ADB

Tags:

android

adb

I am trying to remove a file on my android using a single ADB command.

I understand you can just do adb shell and then remove the file using rm.

But I need it to be a one line execution.

I’ve tried:

adb rm-f /directory/file.txt

adb shell rm-f /directory/file.txt

Both don’t delete the file I want.

like image 295
Kenny Ye Avatar asked Jan 21 '19 05:01

Kenny Ye


People also ask

How do I remove offline devices from adb?

Disconnect the USB connection—or turn off the device's Wi-Fi if you're connected over Wi-Fi. Close Android Studio/Eclipse/other IDE. Run adb kill-server to ensure adb is not running. Restart your Android device.


2 Answers

Delete file on android:

adb shell rm sdcard/download/file.ext
like image 171
Zimba Avatar answered Oct 07 '22 02:10

Zimba


I noticed in your comments you are looking for one line execution since you're gonna be using Python. Well as an alternative you could use the subprocess module to write to stdout allowing you to execute as many commands of choice

for example

import subprocess

process = subprocess.Popen([r'adb', 'arg1', 'arg2'], stdout=subprocess.PIPE,stdin=
subprocess.PIPE) #start adb
process.stdin.write('shell \n') # Parse in input into the program
process.stdin.write('rm *\n') # Parse in second input
line=process.stdout.readline() # Read a line from stdout

like image 21
SuperCode Avatar answered Oct 07 '22 03:10

SuperCode