Categories: Snippets

Create zip archive excluding specific Files & Directories

  • Create archive of all files under public_html directory ignoring all files and folders including text backup in there named
    # zip -r public_html.zip public_html -x *backup*
    
  • Create archive of all files under httpdocs directory ignoring .svn or .git files and directories.
    # zip -r httpdocs.zip httpdocs --exclude *.svn* --exclude *.git*
    
  • Create archive of all files under httpdocs directory ignoring all files and directories ending with with .log.
    # zip -r httpdocs.zip httpdocs --exclude "*.log"
    
  • Exclude .git file and node_modules directory
    $ zip -r [target_file] [source_file] -x *.git* node_modules/\*
    
  • Exclude .git file and files in node_modules directory, but keep node_modules directory
    $ zip -r [target_file] [source_file] -x *.git* node_modules/**\*
  • Exclude cache, backups, uploads directory, but keep node_modules directory (Current date for the generated file)
    $ sudo zip -r /var/www/backup/backup$(date +"%Y-%m-%d").zip  /var/www/html -x "*cache*" -x "*backups*" -x "*uploads*"

 

Recent Posts

How To Troubleshoot Socket Errors in MySQL – Ubuntu

MySQL manages connections to the database server through the use of a socket file, a special…

5 years ago

How to remove .html, .php, etc (extension) from URL?

To remove the .html extension from your urls, you can use the following code in…

5 years ago

Ubuntu with Apache2: Installing and Configuring Your SSL Certificate

Use free/paid SSL certificates https://www.sslforfree.com Enable SSL Module Replace 'default-ssl' with the real site name…

5 years ago

how to use sudo command to install .tar.gz?

To install some file *.tar.gz, you basically would do: Open a console, and go to…

6 years ago

Change ownership of the directory in ubuntu

The chown command has the following syntax: [crayon-66368973318e8445840681/] So in your example command it is your primary…

6 years ago

failed to retrieve share list from server connection refused ubuntu 18.04

How to Save: To save in nano use "CTRL-O", then "CTRL-X". Tip: Replacing sudo nano with gksudo gedit gives you a…

6 years ago