質問

I am working on a project, where compilation of the project involves, zipping up various files and folders and subfolders (html/css/js) selectively. Working on the windows platform, and I could continue to just use the CTRL+A and then SHIFT-click to unselect, but it does get a little tedious. I am working with cygwin, so I was wondering if it is possible to issue a command to zip selected files/folders recursively whilst excluding others, in one command? I already have zip command installed, but I seem to be zipping up the current zip file too and the .svn file too.

I would like this to be incorporated into a shell script if possible, so the simpler the better.

役に立ちましたか?

解決

After reading the man pages, I think the solution that I was looking for is as follws:

  • needs to recurse directories (-r),
  • needs to exclude certail files/directories (-x)
  • It works in the current directory, but the . can be replaced with the path of any directory

    zip -x directories_to_exclude -r codebase_latest.zip .

I have incorporated this into a short shell script that deletes files, tidy up some code, and then zips up all of the files as needed.

他のヒント

You should read man page of zip command:

-R
       --recurse-patterns
              Travel the directory structure recursively starting at the current directory; for example:

                     zip -R foo "*.c"

              In this case, all the files matching *.c in the tree starting at the current directory are stored into a zip archive named foo.zip.  Note that *.c will match
              file.c, a/file.c and a/b/.c.  More than one pattern can be listed as separate arguments.  Note for PKZIP users: the equivalent command is

                     pkzip -rP foo *.c

              Patterns  are relative file paths as they appear in the archive, or will after zipping, and can have optional wildcards in them.  For example, given the cur‐
              rent directory is foo and under it are directories foo1 and foo2 and in foo1 is the file bar.c,

                     zip -R foo/*

              will zip up foo, foo/foo1, foo/foo1/bar.c, and foo/foo2.

                     zip -R */bar.c

              will zip up foo/foo1/bar.c.  See the note for -r on escaping wildcards.

You can also have a look HERE

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top