如何从当前时间戳获取shell输出。 Linux,unix

时间:2012-09-13 21:39:05

标签: android linux shell unix adb

在许多shell命令中,输出是连续的事件流,例如系统日志。我只需要查看从现在或当前系统时间的输出。 这是我从adb logcat获得的程序输出,

09-03 17:12:04.562   479   957 I ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity } from pid 1230
09-03 17:12:04.687   479  1030 I ActivityManager: Start proc com.amazon.mShop.android for activity com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity: pid=19164 uid=10158 gids={1006, 3003}
09-03 17:12:05.593   479   912 I ActivityManager: Starting: Intent { dat=?paramSuggestionText=cell%20phone flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 17:12:05.796   479   620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity: +186ms (total +1s119ms)
09-03 17:12:08.601   479   620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity: +3s925ms
09-03 17:12:08.601   479   620 I ActivityManager: Resumed Activity: com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity totalTime: 4037 ms
09-03 17:13:35.742   479   957 I ActivityManager: Starting: Intent { act=intentActionStartActivity flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.categoryBrowse.CategoryBrowseActivity } from pid 19164
09-03 17:13:36.007   479   620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.categoryBrowse.CategoryBrowseActivity: +222ms
09-03 17:13:53.328   479   957 I ActivityManager: Starting: Intent { dat=?&paramSuggestionFilters=s%3An%3A%2C%3A4991425011%0As%3An%3A%2C%3A4991426011%0As%3An%3A%2C%3A5088769011%0As%3An%3A%2C%3A5263615011&paramDepartmentName=Programs flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 17:13:53.484   479   620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity: +145ms

它是一个连续的流,显示系统启动时的事件,但我只需要来自当前系统时间的日志。那么,我该如何实现呢?

2 个答案:

答案 0 :(得分:1)

根据adb手册,可以分两步完成:

  1. 使用logcat -c
  2. 清除日志
  3. 使用常规logcat电话
  4. 继续进行日志监控

    如果将它们组合在一起,我想只需运行logcat -c && logcat即可。

答案 1 :(得分:0)

我的问题用logcat -c选项解决了。更通用的解决方案是使用tail -f命令行选项。虽然它不是非常准确但有效。