2

I am trying to set the timestamp of a bunch of files on my android device using adb shell.

For one reason or another running touch with a specific provided timestamp does not work. In addition file globbing is not working on the android busybox shell using touch.

So I have resorted to a shell script that runs the touch command on all the files in a folder.

for file in `ls`; do touch "$file"; done

the problem it is not running the command in any specific order, when I want it run in reverse alphabetical order with the guarantee that it will be done serially such that a.png timestamp is always a later time than b.png.

Is this possible?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Scorb
  • 604
  • 3
  • 12
  • 25

2 Answers2

1

You can use touch to set a time into the future.

T=$(date +%s)
for file in $(ls | sort -r); do
  touch -t $(date '+%Y%m%d%H%I.%S' --date="@$T") $file
  let T=$T+1
done

If you are missing sort on the device, make sure you have busybox installed.

HostFission
  • 347
  • 1
  • 7
0

Is this possible?

Yes, and no. Not with high performance. The sticking point is that you specify "a.png timestamp is always a later time than b.png", which I imagine relates to how some Makefile deals with them. Trouble arises if your filesystem only keeps CTIME stamp to one-second resolution. So I propose this:

for file in `ls | sort -r`; do touch "$file"; sleep 1; done

Yeah, I know, the sleep is pretty gross. But that's likely what you need to have make operate predictably.

J_H
  • 636
  • 4
  • 8
  • Thank you for the reply, but I am in the android adb shell, and it has a limited set of the command line functionality. Unfortunately I get this....." sort: not found". :( – Scorb Sep 05 '17 at 01:20
  • You could ship `ls` results back to your host. Sort and iterate on the host, doing sleep 1 and issuing the various adb `touch` commands. – J_H Sep 05 '17 at 03:08
  • what about `ls -r` ? – JJoao Sep 05 '17 at 13:21