0
我最近創建了我的第一個bash腳本,並且遇到了完善它的操作的問題。我試圖將某個文件夾從一個本地驅動器複製到網絡驅動器。如何在成功複製(Mac OSX)後在bash中刪除文件夾?
我有刪除文件夾,一旦它們被複制的問題,有時該文件夾將是空的內容,但文件夾本身將保持,其他時間什麼都不會發生。在rsync完成複製後,是否有更好的方法來嘗試刪除文件夾?我試圖排除實時電視緩衝區文件夾,但實際上,如果需要的話,我可以把它吹走而不會有任何後果。
#!/bin/bash
network="CBS"
useracct="tvcapture"
thedate=$(date "+%m%d%Y")
folderToBeMoved="https://stackoverflow.com/users/$useracct/Documents"
newfoldername="/Volumes/Media/TV/$network/$thedate"
ECHO "Network is $network"
ECHO "date is $thedate"
ECHO "source is $folderToBeMoved"
ECHO "dest is $newfoldername"
mkdir $newfoldername
rsync -av $folderToBeMoved/"EyeTV Archive"/*.eyetv $newfoldername --exclude="Live TV Buffer.eyetv"
# this fails when there is more than one *.eyetv folder
if [ -d $newfoldername/*.eyetv ];
then
#this deletes the contents of the directories
find $folderToBeMoved/"EyeTV Archive"/*.eyetv \(! -path $folderToBeMoved/"EyeTV Archive"/"Live TV Buffer.eyetv" \) -delete
#remove empty directory
find $folderToBeMoved/"EyeTV Archive"/*.eyetv -type d -exec rmdir {} \;
fi
儘管OS X支持ECHO等大寫命令,但您應該養成使用小寫字母的習慣,因爲沒有其他基於Unix的平臺支持大寫的Bash命令。 – 2010-03-22 22:09:44