移動目錄中的所有檔案(RPi 上的特定少數檔案除外)

移動目錄中的所有檔案(RPi 上的特定少數檔案除外)

我正在嘗試編寫一個程序,該程序將遠端更新遠端 Raspberry Pi 4b 上目錄中的所有檔案。我知道需要保留在目錄中的文件的名稱,並且這些文件永遠不會改變。我見過一些例子,其中命令 a la:
mv * !(filetostay) /destination
將跳過想要保留的特定文件,但是當我想跳過多個文件時,有沒有辦法執行該命令?此外,這些文件不是按字母順序或我能想到的任何其他方式連續的,我只知道文件的名稱。

我嘗試執行以下命令:
shopt -s extglob
mv * !(file1|file2) destination
但 RPi 不喜歡它所說的語法
mv: cannot move 'destination' to a subdirectory of itself, 'destination/destination'
mv: warning: source directory 'destination' specified more than once
mv: cannot stat 'file1': No such file or directory
mv: cannot stat 'file2': No such file or directory

答案1

嘗試

mv !(file1|file2) destination

額外的星號表示 pwd 中每個非隱藏檔案的列表

相關內容