How can I compact directory except specific folder?

Asked

Viewed 2,031 times

2

Need with SSH to compact a directory except a specific folder within that directory.

  • briefcase: /public_html

  • except for: /public_html/wp-content/uploads/Vista/

How can I perform this operation? I performed a command that was actually deleting the files from except for but that’s not what I want.

2 answers

3


Use the argument --exclude of command tar:

tar -pczf public_html.tar.gz /public_html/ --exclude "/public_html/wp-content/uploads/Vista"
  • This will not delete the files from /View right?

  • No. It will delete the files only from the compressed file.

  • I cannot delete the files.

  • 1

    @Marcosvinicius he meant it will not add to the compressed when said "It will delete the files only from the compressed file"

  • 1

    Rest assured. The argument --exclude refers to the command tar, has nothing to do with the file system or anything like that.

  • And when I use zip ?

Show 1 more comment

1

You can use the parameter --exclude of tar to compress everything but the specified directory/file.

Example with bzip2 compression:

tar jcvf arquivo.tar.bz2 --exclude="/public_html/wp-content/uploads/Vista/" /public_html
  • This will not delete the files from /View right?

  • @Marcosvinicius No. The parameter exclude serves for you to specify files that will be ignored for tar, that is, at the time of compression, these files will not be included.

  • And when it’s ZIP ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.