Friday, September 20, 2013

A clever command

Problem:
I have a bunch of log files in a directory on my SDCard on my Android device.  I want to pull them off the devices but you can't use ADB to pull multiple files - so this is a command to do that:

adb shell ls /some/dir | awk '{print "/some/dir"$0}' | tr '\r' ' ' | xargs -n1 adb pull

ok break that down: here is what's going on:

adb shell ls /some/dir - this outputs the files in the path but just the file name
| awk '{ print "/some/dir"$0   - this changes the file names to full path names
| tr '\r' ' ' - this formats the text so that xargs can understand the command correctly
xargs -n1 adb pull - executes the adb pull command with the absolute path name