segunda-feira, 8 de outubro de 2018

Compactar e Descompactar arquivo .zip indicando as pastas

Uma dúvida que intriga os iniciantes Linux, é o fato  de descompactar um arquivo .zip e ele abrir todos os arquivos a própria pasta, mesclando todos os arquivo, e não criando uma nova pasta e descompactando os arquivos dentro.

Primeiramente vou gerar 3 arquivos de texto comuns, e coloar um texto dentro:

vim a.txt
vim b.txt
vim c.txt

LISTAR OS ARQUIVOS 
$ ls -lhs
4,0K -rw-r--r-- 1 hudson hudson  836 out  8 00:34 a.txt
4,0K -rw-r--r-- 1 hudson hudson 1,7K out  8 00:36 b.txt
4,0K -rw-r--r-- 1 hudson hudson 2,5K out  8 00:36 c.txt

COMPACTAR TODOS OS ARQUIVOS PARA UMA NOVO ARQUIVO
$ zip -r arquivo.zip a.txt b.txt c.txt 
  adding: a.txt (deflated 46%)
  adding: b.txt (deflated 72%)
  adding: c.txt (deflated 81%)

LISTAR OS ARQUIVOS
$ ls -lhs
4,0K -rw-r--r-- 1 hudson hudson 1,8K out  8 00:43 arquivo.zip
4,0K -rw-r--r-- 1 hudson hudson  836 out  8 00:34 a.txt
4,0K -rw-r--r-- 1 hudson hudson 1,7K out  8 00:36 b.txt
4,0K -rw-r--r-- 1 hudson hudson 2,5K out  8 00:36 c.txt


DESCOMPACTAR O ARQUIVO PARA DENTRO DE OUTRA PASTA
$ unzip arquivo.zip -d arq
Archive:  arquivo.zip
  inflating: arq/a.txt               
  inflating: arq/b.txt               
  inflating: arq/c.txt 
  
  
LISTAR OS ARQUIVOS  
$ ls -lhs
total 20K
4,0K drwxr-xr-x 2 hudson hudson 4,0K out  8 00:45 arq
4,0K -rw-r--r-- 1 hudson hudson 1,8K out  8 00:43 arquivo.zip
4,0K -rw-r--r-- 1 hudson hudson  836 out  8 00:34 a.txt
4,0K -rw-r--r-- 1 hudson hudson 1,7K out  8 00:36 b.txt
4,0K -rw-r--r-- 1 hudson hudson 2,5K out  8 00:36 c.txt


ENTRAR DENTRO DO NOVO DIRETÓRIO "arq" E LISTAR OS ARQUIVOS
$ cd arq/
$ ls -lhs
4,0K -rw-r--r-- 1 hudson hudson  836 out  8 00:34 a.txt
4,0K -rw-r--r-- 1 hudson hudson 1,7K out  8 00:36 b.txt
4,0K -rw-r--r-- 1 hudson hudson 2,5K out  8 00:36 c.txt