繁体   English   中英

如果目标文件夹还包含同名文件,则移动文件并重命名

[英]Move a file and rename it if the destination folder contains also a file with the same name

对不起,我的英语不好。 我想将文件从桌面移动到用户的输入目的地。 如果目的地也有一个同名的文件,我如何要求用户重命名文件,以便他可以将它们都放在目的地文件夹中? 我现在有这个:

#!bin/bash
echo "path"
read path
echo "Do you want to move code files somewhere else?"
read -t 5 y
if [[ $y = 'yes' ]] ; then
echo "Tell me where:"
read mydest
find $path -type f \( -name "*.c" -or -name "*.cxx" -or -name "*.cpp" -or -name "*.cc" \) );do
mv ???
fi 

演示使用mv和开关-i (交互式)和--backup

$ echo foo > foo              # making test files
$ echo bar > bar
$ mv -i --backup foo bar      # mving foo
mv: overwrite 'bar'? y        # -i caused this
$ cat bar                     
foo                           # mv caused this
$ cat bar~                    # --backup caused this
bar

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM