Как я могу удалить все файлы в одной папке за вычетом одного файла (.zip) из командной строки? Я использую bash для ssh на моем сервере, где я хочу это сделать. Я знаю, что могу использовать rm -rf *
находится в этой папке, но мне нужно сохранить заархивированный файл, поскольку он содержит все новые файлы для замены других. Как я могу сделать это из командной строки?
$ shopt -s extglob
$ rm -fr !(*.zip)
info "(bash) Pattern Matching"
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching opera‐
tors are recognized. In the following description, a pattern-list is a list of one or more patterns sep‐
arated by a |. Composite patterns may be formed using one or more of the following sub-patterns:
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
find . ! -name 'file.zip' -delete