簡體   English   中英

指定要使用wget下載而不覆蓋的文件名

[英]Specify file name for download with wget without overwriting

我已經知道您可以通過-O參數指定使用wget完成的下載的文件名。 但是如果文件已經存在,它將被覆蓋。 如果您未指定文件名,則wget永遠不會覆蓋文件,它只會附加.1,.2,.3等。 我想為我指定的文件名添加附加解決方案。 那可能嗎?

這是一個函數,如果需要查找尚不存在的文件名,它將在數字后附加數字:

newfile () {
    fname=$1
    count=0
    while [ -e "$fname" ]
    do
        fname="$1.$((++count))"
    done
    echo "$fname"
}

用法示例:

$ ls
$ newfile abc
abc
$ touch abc
$ newfile abc
abc.1

使用wget ,您可以將其用作:

wget http://example.com/index.html -O "$(newfile something)"

您是否嘗試過使用-nc--no-clobber參數? 它會跳過覆蓋文件的下載嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM