【问题标题】:Find last modified file in adb shell在 adb shell 中查找最后修改的文件
【发布时间】:2014-09-28 10:19:35
【问题描述】:
我正在尝试通过 adb shell 查找上次修改的文件。问题是像 less、head、tail、awk、cut 这样的命令在 adb shell 中不可用。
有什么方法可以让我仅使用 ls 和 grep 找到上次修改的文件?文件名按排序顺序,执行 ls -l 最后显示最后修改的文件。
【问题讨论】:
标签:
android
linux
shell
adb
【解决方案1】:
您可以使用 shell(数组)的内置功能来实现:
IFS=$'\n' # Using only newline as delimiter (ignore tabs and spaces)
output=(`ls -l`) # Save output as array (each position is one line)
lines=${#output[@]} # Calculate the number of lines
echo ${output[$((lines-1))]} # Print the last line from output
如果你只想要文件名,你可能会更棘手:
IFS=$'\n'
output=(`ls -l`)
lines=${#output[@]}
IFS=$' '
file_line=(${output[$((lines-1))]})
file_name=()
index=0
for part in ${file_line[@]}; do
if [[ $index -gt 4 ]]; then file_name+=($part); fi
index=$((index+1))
done
echo ${file_name[@]}
我希望这些会有所帮助。