tar extracted archive removes version - bash

I have a zipped archive version 0.0.1: myarch_0.0.1.tar.gz
When I extract it with tar, everything is unzipped and extracted in a myarch folder, stripping the version number.
ls
myarch_0.0.1.tar.gz
tar -zxvf myarch_0.0.1.tar.gz
ls
myarch/ myarch_0.0.1.tar.gz*
I want the extracted folder to be named: myarch_0.0.1/
How do I keep my version number stuck to the extracted folder name?

The name of an archive file, and the name of the files inside, have nothing to do with each other in general. If you want extracted directories to have a certain name, with a version number, then you have to create the archive with so named directories.
In this example, the extracted content is a directory named myarch, instead of your desired myarch_0.0.1. You can rename the directory and recreate the archive:
mv myarch myarch_0.0.1
tar zcf myarch_0.0.1.tar.gz myarch_0.0.1
That's it. When you untar this new archive, you will get a directory named myarch_0.0.1, simply because that's what you put inside. Even if you rename this file to mickeymouse.tar.gz, when you untar it, you will still get a directory named myarch_0.0.1, simply because that's what's inside the archive. Nothing to do with the filename of the archive.

Related

Get specific file from .tar file within a Bat file

I want to extract a specific file named WholeImage.jpg from a .tar file in Windows.
I got it working in one specific case, in which I specify the exact filelocation in the .tar file:
tar -xf %~1 --strip-components 5 InspectionProjectList/InspectionProject0718/InspectionProgram001/Sensing/Board0003/WholeImage.jpg
The --strip-components 5 is to get rid of the unnecessary folders while extracting the wanted file.
However the filepath for the WholeImage.jpg changes from tar file to tar file.
The parts that change are noted here witd a dollar sign:
InspectionProjectList/InspectionProject$$$$/InspectionProgram$$$/Sensing/Board$$$$/WholeImage.jpg

Is it possible to zip multiple files without a parent directory on macOS?

I have two files that I would like to zip, a.txt and b.txt. I'd like to zip them into a file, called my.zip, in such a way that when my.zip is unzipped, the two files are placed into the current directory without being placed in a directory of any kind.
This is what I have tried so far, from within the directory that contains both files:
zip ../my.zip *
and
zip -j my.zip a.txt b.txt
Those commands create a file called my-zip that when unzipped, creates a directory called my-zip, with the two files inside of it. Instead, I'd like the files to be placed into the current directory, without being contained in a directory called my-zip.
EDIT:
To clarify, the way I am unzipping it is by double-clicking the zip file via Finder on OS X
How did you unzip the my.zip file? I just tried your commands and worked fine as expected. Commands that I ran,
$ zip my.zip a.txt b.txt
$ unzip my.zip
However, when I right click the file my.zip (in Nautilus file manager) and click 'Extract Here', it creates a folder called my and puts the contents in there.

Name not matched in creating zip folder with bash

I'm trying to create a zip folder in a bash script that contains the current date (YYYY_MM_DD).
I have this code:
currentArchive=$(date '+%Y_%m_%d')
zip -r ./aktuell ./Archive/${currentArchive}-bkt
But when I run the script I get the following error:
zip warning: name not matched: ./Archive/2017_03_30-bkt
I want the folder "aktuell" as a zip folder named "2017_03_30-bkt.zip" in the folder "Archive". The current folder "aktuell" exists.
What am I doing wrong?
You have the source and destination directories backwards in your zip command. Also, make sure the destination directory exists before executing zip.
currentArchive=$(date '+%Y_%m_%d')
mkdir -p ./Archive/
zip -r ./Archive/${currentArchive}-bkt ./aktuell

Zip folder created by shell script not opening

I am using the below script to zip the folder and it contents :-
cd /home/fs/Inbnd/
pwd
tar -cvf Image_test_new.zip Image
chmod 777 *
chown fusionc:staff *
The file image.zip is getting created successfully. But the file is not opening and showing an error :
Is there an error in the ststement I am using to zip?
tar -cvf makes a tar ball, not a zip archive. You can verify this in Linux, before trying to open it in Windows.
touch not_going_to_be_a_zip
tar -cvf not_really_a.zip not_going_to_be_a_zip
unzip not_really_a.zip
Archive: not_really_a.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of not_really_a.zip or
not_really_a.zip.zip, and cannot find not_really_a.zip.ZIP, period.
The zip utility does a good job at making zip archives.
touch will_be_a_zip
zip i_am_a.zip will_be_a_zip Archive: i_am_a.zip
testing: will_be_a_zip OK
No errors detected in compressed data of i_am_a.zip.
unzip -t i_am_a.zip
Archive: i_am_a.zip
testing: will_be_a_zip OK
No errors detected in compressed data of i_am_a.zip.
Note: unzip -t will test the archive only, make sure its okay before trying it in Windows.
If you cannot use the standard approach like zip/unzip and if you have JDK installed on your machine then you can use the jar utility from JDK's bin folder.
To zip a file
jar cvf zip_file_name.zip image.jpg
The only overhead is that it will add a META-INF folder with a file named MANIFEST.MF in it, which you can delete after extracting the zip file.
Try to use zip command instead of tar command.

move files to .zip archive in windows command line

I wanted to know how to move files to a .zip archive. I'm using this code: xcopy C:\Folder C:\AnotherFolder\zippedFolder.zip. This copies the files from C:\Folder DIRECTLY into the archive, but I want to have that file in the archive (so i can doubleclick the archive and see the file unopened).
Want to do this to create an excel file with a .cmd
Use -m to import a file to a ZIP archive.
I found this on StackOverflow maybe it helps you.
How to move a file in to zip uncompressed, with zip cmd tool
But be careful it deletes the source file after it adds it to the archive. See the link for more details.
UPDATE
Instructions from this site. http://linux.about.com/od/commands/l/blcmdl1_zip.htm.
-m moves the specified files into the ZIP archive; actually, this deletes the target directories/files after making the specified ZIP archive.
If a directory becomes empty after removal of the files, the directory is also removed. No deletions are done until zip has created the archive without errors. This is useful for conserving disk space, but is potentially dangerous so it is recommended to use it in combination with -T to test the archive before removing all input files.
zip -m yourfile zip.file

Resources