Vinicius Peres
Vinicius Peres

Reputation: 101

How to compress files in a directory without subsequent directories?

I need to compress files and directories within a specific directory. And when unpacking have only the files and directories, not the subfolders.

tar (GNU tar) 1.28

tar czvf /opt/files/files.tar.gz /var/www/html/*

Ex:
/var/www/html/1
/var/www/html/2
/var/www/html/3
/var/www/html/4

Ok

tar xzvf files.tar.gz

tree
├── files.tar.gz
└── var
    └── www
        └── html
            ├── 1
            ├── 2
            ├── 3
            ├── 4

I would like to only get the files and directories (1,2,3 and 4) within html, without the var, www and html subfolders

Upvotes: 0

Views: 50

Answers (1)

blue112
blue112

Reputation: 56572

Change your cwd before running the command :

cd /var/www/html/ && tar czvf /opt/files/files.tar.gz *

Upvotes: 1

Related Questions