簡體   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