How to exclude files while zipping folder - bash

zip -r --exclude=*.html "${getFilePath('assets')}" "."
How do I exclude files named "version" and ".htaccess"?
I tried smth. like
zip -r --exclude=*.html version .htaccess "${getFilePath('assets')}" "."
but it exclude them viz. image and I can't understand why.
P.S. the "assets" folder above "favicons" folder isn't the one on which I'm performing the command, everything you're seeing is under the another assets file, which is zipped.

Related

How do I copy files listed in a .txt into a new folder?

I have a .txt list of filenames that I would like to copy into a new folder. The filenames take the form: 0-01-199898988999.mp4. I can use the list of file names to copy files into a new folder using the following code.
cp `cat list.txt` new_folder/
However, this only works when the files I want to copy, the .txt file, and the new folder are all in the same directory, and all of my files to copy are organized into subfolders within the directory.
FolderA
->list.txt
->new_folder
->SubA
-->0-01-199898988999.mp4
-->0-02-199898988999.mp4
-->0-03-199898988999.mp4
->SubB
-->0-04-199898988999.mp4
-->0-05-199898988999.mp4
-->0-06-199898988999.mp4
-->0-06-199898988999.mp4
How can I modify the code to search through the subdirectories of folder A?
I've tried using --parents, but it hasn't worked.
cp -v --parents `cat list.txt` /new_folder
I've been searching around for answers, but most versions of this problem involve a list with the unique directory names for each file (which I don't have), copying all the files within the subdirectories, or searching by extension instead of file name.

How do I unzip a specific folder within a zipped file, and exclude some specific folder within it?

I have a zipped file:
main.zip
And I want to unzip only some folders present in the zipped folder while excluding the .git pack file.
The folder structure in main.zip is as follows:
main.zip -> main_folder -> folder1, folder2... and I want to extract only folder2 from the zipped file, but this folder2 contains the .git folder with packed files, which I don't need.
So far I have tried :
unzip main.zip "main_folder/folder2/*" -d ~ path/to/some/directory
!(*.git) will exclude the files ending with .git, but how do I integrate this in the command above?
The exclude option works!
We just need to provide a path to the files to be excluded!
unzip main.zip "main_folder/folder2/*" -x "main_folder/folder2/*.git/*" -d path/to/some/directory

Chilkat unzip files only from root directory

zip.UnzipMatching("qa_output","*.xml",true)
With this syntax I can unzip every Xml in every directory from my zip file and create the same directory structure.
But how can I unzip only the xml in the root directory?
I cannot understand how to write the filter.
I tried with "/*.xml" but nothing is extracted.
If I write "*/*.xml" I only extract xml files from subdirectory (and I skip the xml in the root directory!).
Can anyone help me?
example of a zip files content:
a1.xml
b1.xml
c1.xml
dir1\a2.xml
dir1\c2.xml
dir2\dir3\c3.xml
with unzipmatching("qa_output","*.xml", true) I extract all this files with the original directory structure, but I want to extract only a1.xml, b1.xml and c1.xml.
Is there a way to write filter to achieve this result, or a different command, or a different approach?
I think what you want is to call UnzipMatchingInto: All files (matching the pattern) in the Zip are unzipped into the specfied dirPath regardless of the directory path information contained in the Zip. This has the effect of collapsing all files into a single directory. If several files in the Zip have the same name, the files unzipped last will overwrite the files already unzipped.

How to extract all files at once in folders from a tar.gz file

I have a tar.gz file which includes 2 tar files and each tar file includes several folders and subfolders that include my required files.
I want to extract the final files from those subfolders in a directory.
I know I can use something like tar -xzvf but finally, it gives me all the folders and subfolders and the files I needed in those subfolders.
Example file:
file.tar.gz: this file contains 1.tar and 2.tar. 1.tar contains folder1, folder2, ..., folder100. and 2.tar contains foldera, folderb, ..., folderz. My text files are in these subfolders.
I want to extract all of my text files in a user-defined directory without extracting subfolders. my_dir/*.txt
Any help would be much appreciated.
Thank you.

bash zip omit files

I'd like to zip a folder, but zip skips files.
Folder structure is:
main_folder > sub_folder > file2.sql
file11.txt
file12.sql
Main_folder contains sub_folder and two files, subfolder contains one file.
When i use
zip -r $path *
i receive .zip file which contains everything except file11.txt. I tried various options but have not solved the problem. Zip makes correct structure and takes every single file except files from main_folder.
could you try this;
zip -r your.zip * -x file11.txt
man zip;
-x files
--exclude files
Explicitly exclude the specified files..

Resources