How can I zip a file using Cygwin and bzip2? - cygwin

I have downloaded Cygwin and the package to zip files (bzip2) but I cant figure out how to use its command to simply zip a file to another location.
All I want to do is something like:
bzip2 myfile somelocation

You want to use:
bzip2 --keep [file to zip] > [Destination]
Omit brackets when filling in the details.
So, for your example, you would want to say:
bzip2 --keep myfile > somelocation
bzip2 writes to standard output, so you just need to use basic shell tools to direct or pipe this output to your destination. Your destination will be a file, not a folder, so if you want the compressed file to go inside a folder called somelocation, you would want to say something like
bzip2 --keep myfile > somelocation/myfile.bz2
The --keep parameter tells bzip2 not to delete your original file. If you do want to delete it, omit this parameter.
I tested this with my own installation of Cygwin on Windows 8.1.

Related

unziping files in linux folder

in Python I have the following command executed unzip '{dir}ATTOM_RECORDER/*.zip' -d {dir}ATTOM_RECORDER/ as a bash command. The python call works perfectly. my question is about the unzip command itself.
for some reason when unzip is called to expand any relevent zip files in the folder specified, not all the files WITHIN the zip is extracted. There's usually a rpt and a txt file. However, sometimes the txt file is not coming out and I do not have an error command.
How can I ensure the txt file is guaranteed to be extracted before moving on?
Thanks
While you want to unzip your specific zip file. There are many option to decompress any file from zip files. Easiest way is the ā€˜-lā€™ option with unzip command is used to list the contents of a zip file after extracting it.
Syntax: unzip -l [file_name.zip]

Is there a way to access a file inside a .zip in a Linux environment

I want to find a specific line of text inside of a file and print it on my screen using Linux commands. I know I could do:
find -name '[filename]' | xargs grep -i ā€˜[text I'm looking for inside file]'
However, my file is inside a .zip file. I know unzip -l [.zip file name] will list of all files inside of .zip file, but it won't let me access in order to "grep" the information I need.
Is there a solution to this?
The find_zip tool from the open-source Zip-Ada project.
get / download the sources
build with the command gnatmake -P zipada (you get GNAT through apt or yum)
you have now a binary find_zip.
Usage: find_zip archive[.zip] ["]text["]

How to create a Linux compatible zip archive of a directory on a Mac

I've tried multiple ways of creating a zip or a tar.gz on the mac using GUI or command lines, and I have tried decompressing on the Linux side and gotten various errors, from things like "File.XML" and "File.xml" both appearing in a directory, to all sorts of others about something being truncated, etc.
Without listing all my experiments on the command line on the Mac and Linux (using tcsh), what should 2 bullet proof commands be to:
1) make a zip file of a directory (with no __MACOSX folders)
2) unzip / untar (whatever) the Mac zip on Linux with no errors (and no __MACOSX folders)
IT staff on the Linux side said they "usually use .gz and use gzip and gunzip commands".
Thanks!
After much research and experimentation, I found this works every time:
1) Create a zipped tar file with this command on the Mac in Terminal:
tar -cvzf your_archive_name.tar.gz your_folder_name/
2) When you FTP the file from one server to another, make sure you do so with binary mode turned on
3) Unzip and untar in two steps in your shell on the Linux box (in this case, tcsh):
gunzip your_archive_name.tar.gz
tar -xvf your_archive_name.tar
On my Mac and in ssh bash I use the following simple commands:
Create Zip File (-czf)
tar -czf NAME.tgz FOLDER
Extract Zip File (-xzf)
tar -xzf NAME.tgz
Best, Mike
First off, the File.XML and File.xml cannot both appear in an HFS+ file system. It is possible, but very unusual, for someone to format a case-sensitive HFSX file system that would permit that. Can you really create two such files and see them listed separately?
You can use the -X option with zip to prevent resource forks and extended attributes from being saved. You can also throw in a -x .DS_Store to get rid of those files as well.
For tar, precede it with COPYFILE_DISABLE=true or setenv COPYFILE_DISABLE true, depending on your shell. You can also throw in an --exclude=.DS_Store.
Your "IT Staff" gave you a pretty useless answer, since gzip can only compress one file. gzip has to be used in combination with tar to archive a directory.

How do I zip files without compression using batch command

I am writing a batch file in order to make an .ear file. Here is my code snippet:
winrar.exe a -afzip -m5 -ed -pTest -r -ep1 %earName%.ear %extractDest%*
This code compresses the including files which I don't want. How can I just add the files in the "extractDest" to the .ear file without compressing?
You can use command line zip from Info-Zip as follows:
zip -rp0 earname.ear source_dir
-0 means store and don't compress (-r recursive, -p preserve relative path).
Unlike winrar, Info-Zip is open source (no prompts to purchase), and its zip and unzip are true command-line utilities, and very small ones at that.
If you insist on using winrar, you must use option -m0 (instead of -m5), which selects 0 (store) compression level.

Command to zip a directory using a specific directory as the root

I'm writing a PHP script that downloads a series of generated files (using wget) into a directory, and then zips then up, using the zip command.
The downloads work perfectly, and the zipping mostly works. I run the command:
zip -r /var/www/oraviewer/rgn_download/download/fcst_20100318_0319.zip /var/www/oraviewer/rgn_download/download/fcst_20100318_0319
which yields a zip file with all the downloaded files, but it contains the full /var/www/oraviewer/rgn_download/download/ directories, before reaching the fcst_20100318_0319/ directory.
I'm probably just missing a flag, or something small, from the zip command, but how do I get it to use fcst_20100318_0319/ as the root directory?
I don't think zip has a flag to do that. I think the only way is something like:
cd /var/www/oraviewer/rgn_download/download/ && \
zip -r fcst_20100318_0319.zip fcst_20100318_0319
(The backslash is just for clarity, you can remove it and put everything on one line.)
Since PHP is executing the command in a subshell, it won't change your current directory.
I have also get it worked by using this command
exec('cd '.$_SERVER['DOCUMENT_ROOT'].' && zip -r com.zip "./"');
cd /home/public_html/site/upload/ && zip -r sub_upload.zip sub_upload/
Use the -j or --junk-paths option in your zip command.
From the zip man page:
-j
--junk-paths
Store just the name of a saved file (junk the path), and do not store
directory names. By default, zip will store the full path (relative
to the current directory).

Resources