Compress with zip command of java side linux

If you want to call the zip command of linux on the java side, you can use ProcessBuilder. Example 1: If you keep all directories List commandList = new ArrayList(); commandList.add("-r"); ProcessBuilder pb =new ProcessBuilder(commandList);

Example 2: If the directory is not retained (error if the same file name is used) List commandList = new ArrayList(); commandList.add("-j"); ProcessBuilder pb =new ProcessBuilder(commandList); LINUX zip command list -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

Example 3 What to do in the following cases? Folder format: / home / AB / CD / + Various files and subfolders Input perspective /home/AB/CD/ After compression (/ home / AB / CD / not included) 各種ファイルとサブフォルダ.zip Try it, the command below is good.

pb = new ProcessBuilder("sh", "-c", “zip -r test.zip ./*”)).directory(new File("/home/AB/CD/")); You can also write in the same way. pb = new ProcessBuilder("/bin/sh", "-c", “zip -r test.zip ./*”)).directory(new File("/home/AB/CD/")); pb = new ProcessBuilder("/bin/bash", "-c", “zip -r test.zip ./*”)).directory(new File("/home/AB/CD/"));

Recommended Posts

Compress with zip command of java side linux
Check the memory status of the server with the Linux free command
Check the operating status of the server with the Linux top command
[Linux] OS recovery with restore command
Completion of docker command on Linux
Linux command # 3
Linux command # 5
Adjust file permissions with the Linux command chmod
Summary of Java 11 release status of major Linux distributions
Asynchronous processing with Arduino (Asynchronous processing of processing requests from Linux)
[Linux command] A memorandum of frequently used commands
Linux command list
linux at command
[Linux] Search command
Linux command <Basic 2>
Linux [directory command]
Linux server command
Linux # Command Memo 1
Linux command [read]
Linux [shell command]
[Linux] Command / Knowledge
My linux command
Linux command <Basic 1>
Linux command collection
Linux mkdir command
Linux command basics
[Linux] Git command
Linux (command memory)
[Linux command] Petit data analysis with grep / awk / sort command
The story of replacing Nvidia GTX 1650 with Linux Mint 20.1.
Open Chrome version of LINE from the command line [Linux]
[Linux] Execute git pull regularly with the crontab command
Yum command to access MySQL with Python 3 on Linux
Understand the attributes of Linux files (ls -l command)
Announcing the availability of Java 11 LTS on Amazon Linux 2