安卓shell 移动某个时间之后的文件到另外一个文件夹 命令记录
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -1 -type f -exec ls -l {} \+
shuchushuliang Camera Camera.new
供先测试一下
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -1 -type f -exec mv -iv "{}" /storage/emulated/0/DCIM/Camera.new \;
(/storage/emulated/0/DCIM/Camera.new和/storage/emulated/0/DCIM/Camera.new/ 最后的斜杠加不加都行)
指定具体的日期 尴尬了 发现toybox的这个find不能用newermt
受不了了,toybox啥都不全,老多功能没有,用mt内置的终端了,这个全
测试用:
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -type f -newermt "2024-06-01" ! -newermt "2024-08-01" -exec ls -l {} \;
移动:
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -type f -newermt "2024-06-01" ! -newermt "2024-08-01" -exec mv -iv "{}" /storage/emulated/0/DCIM/Camera.6yue \;
newermt意思就是修改时间modify time比后边的值新的文件
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -type f -newermt "2024-06-01" !-newermt "2024-06-02" -exec ls -l {} \;
find: bad arg '-newermt'
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -type f -newer "2024-06-01" ! -newer "2024-06-02" -exec ls -l {} \;
find: Can't stat 2024-06-01: No such file or directory
-newer FILE newer mtime than FILE
lrwxr-xr-x 1 root shell 6 2009-01-01 08:00 /system/bin/find -> toybox
算了,手算mtime吧 移进去一个完整功能的find更麻烦 用这个网址算https://tl.beer/shijiancha.html
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -168 -mtime +167 -type f -exec ls -l {} \+
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -168 -mtime +167 -type f -exec mv -iv "{}" /storage/emulated/0/DCIM/Camera.6yue \+
-print0 | xargs -0 -I {} mv -iv {} /storage/emulated/0/DCIM/Camera.6yue
还是不行,toybox的xargs没有-I {}这个用法
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -168 -mtime +167 -type f -exec mv -iv "{}" /storage/emulated/0/DCIM/Camera.6yue \+
find: -exec without \;
用-exec ... {} +时,{}必须是+之前的最后一项。这就是他使用mv -t destdir {} +而不是mv {} destdir + 的原因。有人曾使用-exec mv {} destdir ';'代替,但那样会为每个文件执行一次mv 。
-exec mv -iv -t path_B {} +不行,因为toybox的mv没有t参数
ls -l /storage/emulated/0/DCIM/Camera | wc -l
ls -l /storage/emulated/0/DCIM/Camera.new | wc -l
count1=$(ls -l /storage/emulated/0/DCIM/Camera | wc -l)
count2=$(ls -l /storage/emulated/0/DCIM/Camera.new | wc -l)
total=$(expr $count1 + $count2)
echo "$count1 $count2 $total"
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -1 -type f -exec ls -l {} \;
mt管理器
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -type f -newermt "2024-06-01" ! -newermt "2024-06-02" -exec ls -l {} \;
bash: ! : event not found 看起来是不支持newermt
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -168 -mtime +165 -type f -exec mv -iv -t /storage/emulated/0/DCIM/Camera.6yue {} +
终于成功运行了,2975个文件 大概32秒
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -165 -mtime +160 -type f -exec mv -iv "{}" /storage/emulated/0/DCIM/Camera.6yue \;
老方法 3912个文件 大概210秒
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -161 -mtime +155 -type f -exec mv -iv -t /storage/emulated/0/DCIM/Camera.6yue {} +
6225个文件 大概182秒(口数) 这样看来,用+,速度大概快1.5倍,快的不是很明显
find /storage/emulated/0/DCIM/Camera -maxdepth 1 -mtime -155 -mtime +150 -type f -exec mv -i -t /storage/emulated/0/DCIM/Camera.6yue {} +
取消了-v输出信息 3770个文件 大概150秒 快的不是很明显
这样看来,速度瓶颈应该在于find,find在大量文件的目录中速度太慢。有时间试一下fd的并行查找,暂时没时间整了
安卓mt管理器图形界面文件移动速度测试
5232个文件,大概150秒 这样看来这速度跟我费劲半天敲命令行差不多啊。。。
130|cas:/ $ xargs --help
usage: xargs [-0prt] [-s NUM] [-n NUM] [-E STR] COMMAND...
Run command line one or more times, appending arguments from stdin.
If command exits with 255, don't launch another even if arguments remain.
-0 Each argument is NULL terminated, no whitespace or quote processing
-E Stop at line matching string
-n Max number of arguments per command
-p Prompt for y/n from tty before running each command
-r Don't run command with empty input
-s Size in bytes per command line
-t Trace, print command line to stderr
find --help
usage: find [-HL] [DIR...] [<options>]
Search directories for matching files.
Default: search "." match all -print all matches.
-H Follow command line symlinks -L Follow all symlinks
Match filters:
-name PATTERN filename with wildcards -iname case insensitive -name
-path PATTERN path name with wildcards -ipath case insensitive -path
-user UNAME belongs to user UNAME -nouser user ID not known
-group GROUP belongs to group GROUP -nogroup group ID not known
-perm [-/]MODE permissions (-=min /=any) -prune ignore contents of dir
-size N[c] 512 byte blocks (c=bytes) -xdev only this filesystem
-links N hardlink count -atime N[u] accessed N units ago
-ctime N[u] created N units ago -mtime N[u] modified N units ago
-newer FILE newer mtime than FILE -mindepth # at least # dirs down
-depth ignore contents of dir -maxdepth # at most # dirs down
-inum N inode number N -empty empty files and dirs
-type [bcdflps] (block, char, dir, file, symlink, pipe, socket)
-context PATTERN security context
Numbers N may be prefixed by a - (less than) or + (greater than). Units for
-Xtime are d (days, default), h (hours), m (minutes), or s (seconds).
Combine matches with:
!, -a, -o, ( ) not, and, or, group expressions
Actions:
-print Print match with newline -print0 Print match with null
-exec Run command with path -execdir Run command in file's dir
-ok Ask before exec -okdir Ask before execdir
-delete Remove matching file/dir
Commands substitute "{}" with matched file. End with ";" to run each file,
or "+" (next argument after "{}") to collect and run with multiple files.
cas:/storage/emulated/0/DCIM/Camera $ find --version
toybox 0.8.0-android
history命令,输出adb shell的历史命令
cas:/storage/emulated/0/DCIM/Camera $ history
1 cd /storage/emulated/0/DCIM/
2 ls
3 cd Camera
4 ls -l | wc -l
5 find . -mindepth 1 -maxdepth 1 -mtime -3
6 find --help
7 cd ..
8 find
9
10 cd /storage/emulated/0/DCIM/
11 ls
12 cd Camera
13 ls -l | wc -l
14 find . -mindepth 1 -maxdepth 1 -mtime -1 -exec ls -ld "{}" \;
数字加法
8 expr 106042 + 6551
9 expr 99235 +13358(expr: Unexpected extra input '+13358')
10 expr 99235 + 13358