S
S
simple_math2014-02-15 10:35:39
linux
simple_math, 2014-02-15 10:35:39

How to archive with the zip command in Linux?

How to implement such a thing from the console.
For example, I have three files in my folder:
file1.txt
file2.txt
file3.txt
You just need to create their archives next to them with the names saved, like:
file1.txt
file1.zip
file2.txt
file2.zip
file3.txt
file3. zip
I'm dumb

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
iandriyanov, 2014-02-15
@simple_math

If just like in the example, then here:
If otherwise. Then you need to tweak the command. The meaning of a team is this.
ls runs through the directory and pipes everything it finds with a .txt extension to the program's sed editor. Sed truncates extensions using regular expressions to leave filenames for later use.
All this business in the loop leads to the fact that what is executed in the $ () command at the beginning of the line (these are the origins of the shell) is substituted into the $ i variable. And a string is formed for execution.
Here it turns out like this:
zip -9 1.zip 1.txt
zip -9 2.zip 2.txt
....

O
oia, 2014-02-15
@oia

(un)zip --help
coder.v-tanke.ru/viewtopic.php?t=684

C
cjey, 2014-02-15
@cjey

I don't have Linux handy to check but you can use a loop.
(It should look something like)
for i in `ls *.txt`; do zip $i > $i.zip; done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question