hum*_*der 8 command-line directory zip cd-command
我需要创造一个解压缩后的结果保存的目录结构的ZIP压缩文件从指定的目录下。我还需要在不实际切换到目录的情况下执行此操作。
我的问题是类似的,以本。在阅读了大量有关该问题的内容后,我觉得没有任何内容完全回答了我的问题。
例如,我有:
/tmp
/sub_dir
/相关目录
/子文件夹_1/
东西.pdf
东西.xls
/sub_folder_2/
东西.pdf
东西.xls
/sub_folder_3/
东西.pdf
东西.xls
我需要能够执行zip -r /tmp/sub_dir/pertinent_dir.zip /tmp/sub_dir/pertinent_dir/*这样的结果只包含pertinent_dir和以下。同样,无论我当前的目录上下文如何,我都需要这样做。我试过了-j,但这似乎不起作用。也许这是不可能的。有什么我想念的吗?
小智 7
sh -c "cd /tmp/sub_dir/pertinent_dir/../ \
&& zip -r pertinent_dir.zip pertinent_dir/*"
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以使用 jar 而不是 zip:
jar cfM /tmp/sub_dir/pertinent_dir.zip -C /tmp/sub_dir pertinent_dir
Run Code Online (Sandbox Code Playgroud)