How to change a file inside an archive (.ear) file without extracting entire file - linux

I have an .ear file (an archive file like tar / zip) that has a file inside that i want to change.
For example myfile.ear contains 1.txt and i want to change 1.txt to 2.txt and possibly also change some of the content inside 1.txt (like sed does)
I really want to avoid having to extract myfile.ear, change the file and compress it again.
Does anyone know a way to achieve this in linux ?
And if it's not possible, I would also like to know why
Thanks.

EAR files are just JAR files which are just ZIP files. The ZIP format, IIRC, contains metadata and data interleaved, so changing one file (which might be larger/smaller than the file it is replacing) might not fit (or leave a gap), thus in all practical terms the file must be rewritten when doing modifications.

Related

Renaming a file without copying it; any alternative to OverlayFS?

I want to have a "virtual" filesystem like OverlayFS where I can rename the files and folders, but without copying the whole file. I have an archive with over 800TB of Data and the files need to be renamed, but I want to keep the original folder structure and the filenames.
For instance:
I have the 800tb mount on /mnt/archive.
I want an "overlay" mount on /mnt/archive_renamed.
So that a file, for example Data001.bin on /mnt/archive can be renamed on the overlaymount and look something like this /mnt/archive_renamed/Data_from_2014/Data_from_Cats.bin but belongs still to Data001.bin and never touches the underlying mount.
OverlayFS would be perfect if it doesn't need to copy the whole file when renaming it.
Any clue?
In /mnt/archive_renamed, you can use hardlinks to the original files.
Just do "cp -al /mnt/archive /mnt/archive_renamed" and you'll have to folders pointing to the same files.

zipx with xz compression(95)

When using zipx with xz, zip format will be same, only compression method changes to 5F, right?
But my doubt is, when i want to compress a folder with multiple file, how does zip do it using xz? Because, xz only supports to compress one single file..
So winzip might have to do some operation to make the folder and its contents to a single file (operation like tar or cpio)
So what METHOD does it use to archieve all the files into a single one?
We tried to zip the folder with no compression to make it to one file, and apply xz on that, but we need to unzip twice to get the orginal folder.
How does zipx do it in one unzip?
The zip file format compresses each file individually. So it can use xz for that, no problem, which compresses one file. The zip format is individual file compression followed by archiving. Things like .tar.gz or .tar.xz are the opposite, which is archiving followed by compression of the entire archive.

How to create a sub-zip based on the contents of another zip?

I would like to create a zip that contains just a subset based on another zip file. Is there a smarter way to do this than just extracting the specific files and then re-zipping them under a new name?
I'm looking for an efficient way to do this, as the original file will contain thousands and thousands of files and will have a rough size of ~30 GB.
by deleting other stuff e.g.:
zip --delete file.zip junk/*
Second option is by listing zip file with
zipinfo -1 file.zip >list.files
and edit temporally file list to include. Then you
unzip file.zip $(cat list.files)
and create new zip file. Of course the same file can be used for exclusion for zip --delete. Or you can do the same using its on the fly file list in combination with grep for instance.
Check also https://bitbucket.org/agalanin/fuse-zip

Getting files names inside a rar/zip file without unzip

Does anyone know if it is possible to get the name of files inside a rar/zip without having to unrar/unzip the file.. and if yes, is there a way to block it or make difficult..
Thanks
The file names in a zip file are visible even if the data is encrypted. If you want to hide the names, the easy solution is to zip the zip file encrypted.
Later versions of PKZip do have an option to encrypt the file names as well with –cd=encrypt. (cd means central directory.)
The -l flag to unzip(1) does just that:
-l
list archive files (short format). The names, uncompressed file sizes and modification dates and times of the specified files are printed, along with totals for all files specified.
unrar(1) has the l option:
l
List archive content.

multiple file view like DB-view

Is it possible, using bash, to create a view/virtual file that when opened combines 2 files into 1?
example:
FILE_META_1.txt
FILE_META_2.txt
combines into
FILE_META.txt
In general, this is not possible. I assume you mean you want to logically link 2 files without creating a 3rd file that is the sum of the 2 files. I've often wanted this feature also. It would have to be done at the kernel level or via a special file system, maybe use FUSE. UnionFS provides this for directories, but not for files. FuseFile looks like it does what you want. Also take a look at the Logic File System.
You can open them stream-like wise with process substitution:
cat <(cat FILE_META_1.txt; cat FILE_META_2.txt;)
<(*) here expands to a named pipe path which you could open and access like a file for input.

Resources