SanCi

zip打包文件夹(不保留路径)
用zip命令打包文件夹(不保留路径)(不显示目录结构)想将NAS下的webroot/sanci下面的folder文...
扫描右侧二维码阅读全文
03
2018/10

zip打包文件夹(不保留路径)

用zip命令打包文件夹(不保留路径)(不显示目录结构)
想将NAS下的webroot/sanci下面的folder文件夹打包压缩为folder.zip,用 zip -r folder.zip /webroot/sanci/folder ,结果folder.zip压缩包中的文件夹是以/webroot开始的几层目录,也就是说压缩包中包含了文件所在的目录结构,为了安全着想一般是不希望出现/webroot 这些路径的。

可以这样,进入/webroot/sanci 目录再执行zip -r folder.zip folder,这样就没有/webroot 这几层目录了。
具体操作:
cd /web/sanci
zip -r folder.zip folder

-x参数排除目录@eaDir
这里有一个坑:
-x后面不需要空格( 这里我试了N次才发现,网上找的教程都是有空格的)
② 必须要在排除的目录后面加*号,这样@eaDir*才行的
zip -r folder.zip -x"./@eaDir*" folder


使用--help参数可以查看zip命令的更多参数
ziphelp.png

root@Sanci:/# zip --help
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
Zip 3.0 (July 5th 2008). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  The default action is to add or replace zipfile entries from list, which
  can include the special name - to compress standard input.
  If zipfile and list are omitted, zip compresses stdin to stdout.
  -f   freshen: only changed files  -u   update: only changed or new files
  -d   delete entries in zipfile    -m   move into zipfile (delete OS files)
  -r   recurse into directories     -j   junk (don't record) directory names
  -0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
  -1   compress faster              -9   compress better
  -q   quiet operation              -v   verbose operation/print version info
  -c   add one-line comments        -z   add zipfile comment
  -@   read names from stdin        -o   make zipfile as old as latest entry
  -x   exclude the following names  -i   include only the following names
  -F   fix zipfile (-FF try harder) -D   do not add directory entries
  -A   adjust self-extracting exe   -J   junk zipfile prefix (unzipsfx)
  -T   test zipfile integrity       -X   eXclude eXtra file attributes
  -y   store symbolic links as the link instead of the referenced file
  -e   encrypt                      -n   don't compress these suffixes
  -h2  show more help
  -yf  store files/directories that symbolic links point to in an archive
  -cp  codepage, ex: fre,ger,ita,spn,cht,chs,jpn,krn,ptb,rus,dan,nor,sve,nld,plk,ptg,hun,trk,csy

随机一言(显示内容与本文关)
Last modification:October 3rd, 2018 at 10:38 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment