LINUX.ORG.RU
решено ФорумAdmin

Вопросы по применению 7z

 


0

1

Вот это заархивирует всю директорию:

7z a arch.7z
А как заархивировать только файлы 1.doc и 2.doc? Я читал мануал и подозреваю, что то, что я спросил выше, делается через параметр -i, но расшифровать вот это так и не смог:
-i[r[-|0]]{@listfile|!wildcard}
              Include filenames
Ясно, что это регулярное выражение, но как конкретно этим пользоваться?

как конкретно этим пользоваться?

никак. Юзай tar, зачем тебе 7z?

emulek
()
Ответ на: комментарий от emulek

внутри разделители бывают? что он заархивирует, если в директории лежат файлы с именами 1, 2, 12? или как тогда заархивировать все три файла таким способом?

grem ★★★★★
()
Ответ на: комментарий от grem

внутри разделители бывают?

не понял вопрос

что он заархивирует, если в директории лежат файлы с именами 1, 2, 12?

ничего.

если 1.doc, 2.doc, 12.doc, то 1.doc, 2.doc, и НЕ 12.doc

как тогда заархивировать все три файла таким способом?

таким — никак

$ echo {1,2,12}.doc
1.doc 2.doc 12.doc
$ echo {1..7}.doc
1.doc 2.doc 3.doc 4.doc 5.doc 6.doc 7.doc
$ echo {1..7..2}.doc
1.doc 3.doc 5.doc 7.doc
$ echo {a..h..2}.doc
a.doc c.doc e.doc g.doc

emulek
()
Ответ на: комментарий от ser666

возможно так [12]{,2}

так фигня получится ИМХО. [12] работает как звёздочка, звёздочка ловит все файлы, а [12] ловит 1 и 2

{,2} это просто 2.

[12]{,2} поймает 12 и 22.

наверное, я так не извращаюсь.

emulek
()
Ответ на: комментарий от emulek
7z a doc.zip {1,2}{,2}.doc
...
WARNING: Cannot find 1 file

7z a doc.zip [12]{,2}.doc
...
Everything is Ok

я понимаю почему он ругается в первом случае (нет 22.doc), но почему во втором - нет?

ser666
()
Ответ на: комментарий от ser666

я понимаю почему он ругается в первом случае (нет 22.doc), но почему во втором - нет?

ты вообще читаешь, что я пишу? Твоё {,2} — говнокод, садись, 2. Да, просто 2.

А [12] обрабатывается bash'ем так:

1. ищется файл 1 и файл 2

2. если есть только 1 или только 2, то 1 ИЛИ 2 и возвращаются.

3. если есть оба, возвращаются оба: 1 2

4. если нет вообще, возвращается [12]

да, если в пустом каталоге сказать

$ ls *
/bin/ls: невозможно получить доступ к *: Нет такого файла или каталога

emulek
()
Ответ на: комментарий от ser666

проще открыть man bash, и прочитать

Brace Expansion Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to pathname expansion, but the filenames generated need not exist. Patterns to be brace expanded take the form of an optional pre‐ amble, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, fol‐ lowed by an optional postscript. The preamble is prefixed to each string contained within the braces, and the post‐ script is then appended to each resulting string, expanding left to right.

Brace expansions may be nested. The results of each expanded string are not sorted; left to right order is preserved. For example, a{d,c,b}e expands into `ade ace abe'.

A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer. When integers are supplied, the expression expands to each number between x and y, inclusive. Supplied integers may be prefixed with 0 to force each term to have the same width. When either x or y begins with a zero, the shell attempts to force all generated terms to contain the same number of digits, zero-padding where necessary. When characters are supplied, the expression expands to each character lexicographically between x and y, inclusive, using the default C locale. Note that both x and y must be of the same type. When the increment is sup‐ plied, it is used as the difference between each term. The default increment is 1 or -1 as appropriate.

Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expan‐ sion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression. Any incorrectly formed brace expansion is left unchanged. A { or , may be quoted with a backslash to prevent its being considered part of a brace expression. To avoid conflicts with parameter expansion, the string ${ is not considered eligible for brace expansion.

This construct is typically used as shorthand when the common prefix of the strings to be generated is longer than in the above example:

mkdir /usr/local/src/bash/{old,new,dist,bugs} or chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}

Brace expansion introduces a slight incompatibility with historical versions of sh. sh does not treat opening or clos‐ ing braces specially when they appear as part of a word, and preserves them in the output. Bash removes braces from words as a consequence of brace expansion. For example, a word entered to sh as file{1,2} appears identically in the output. The same word is output as file1 file2 after expansion by bash. If strict compatibility with sh is desired, start bash with the +B option or disable brace expansion with the +B option to the set command (see SHELL BUILTIN COM‐ MANDS below).

emulek
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.