I'm trying to do a pipe operation on my Android device through adb
(this is for an automated script).
The operation is to fetch the most recently modified file in a particular directory and then delete it.
Let us say this file is file.txt
and it is in /sdcard/Android/data/my.app.package
on the Android device.
When I try to do adb shell ls -t /sdcard/Android/data/my.app.package | head -1 | xargs rm -f
it throws the error:
rm: file.txt: No such file or directory
This is because it expects the full path.
So then I tried ls -t /sdcard/Android/data/my.app.package | head -1 | xargs ls -d | xargs rm -f
but it complains with the same error.
Perhaps I need to pass in the $PWD
along with the file name to xargs
. How can I do that, or is there a better way to do this?
Edit: I have now tried ls -t sdcard/Android/data/my.app.package | head -1 | xargs -I '{}' ls sdcard/Android/data/my.app.package/'{}'
and while a similar command works correctly on the Linux system as expected, it does weird stuff on the Android device. Possibly some missing implementation of xargs
on Android stack.