在OSX中展平文件结构时自动覆盖

时间:2018-09-17 10:48:44

标签: bash macos command-line find mv

我试图在OSX中展平一个包含许多重复文件的目录。

到目前为止,我有....

find /directory -mindepth 2 -type f -exec mv -i '{}' /directory ';'

但这多次回答了我:

overwrite /directory/file.xml? (y/n [n]) 
not overwritten

请有人帮助我标记自动接受是/否,并在上面的命令中将其包含在其中吗?

预先感谢

1 个答案:

答案 0 :(得分:3)

对于-f命令,您应该使用选项-i而不是mv

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.)