【问题标题】:Auto overwrite when flattening file structure in OSX在 OSX 中展平文件结构时自动覆盖
【发布时间】:2019-02-21 06:39:11
【问题描述】:
我试图在 OSX 中展平一个包含许多重复文件的目录。
到目前为止,我已经......
find /directory -mindepth 2 -type f -exec mv -i '{}' /directory ';'
但这回答了我很多次:
overwrite /directory/file.xml? (y/n [n])
not overwritten
请有人帮我设置自动接受是/否的标志,以及它应该包含在上述命令中的什么位置?
提前致谢
【问题讨论】:
标签:
bash
macos
command-line
find
mv
【解决方案1】:
对于mv 命令,您应该使用选项-f 而不是-i
find /directory -mindepth 2 -type f -exec mv -f '{}' /directory ';'
在mv的手册中:
-f Do not prompt for confirmation before overwriting the destination path. (The -f option overrides any
previous -i or -n options.)
-i Cause mv to write a prompt to standard error before moving a file that would overwrite an existing file.
If the response from the standard input begins with the character `y' or `Y', the move is attempted.
(The -i option overrides any previous -f or -n options.)