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

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.

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

Finding and copying files in subfolders to a unique folder giving them their path names

I need to do a bash script in order to copy all files which are in various subfolders and sub-subfolders of a main directory to a unique another folder while giving them a new name indicating their source.
Source paths and files are like:
MainDir/SubFolderX/SubSubFolderXY/fileZ.dat
MainDir/UnknowName../AnotherUnknowName../AnyFile.anyExtension
... Etc
Destination folder with renamed files would be:
NewDir/SubFolderX_SubSubFolderXY_fileZ.dat
NewDir/UnknowName.._AnotherUnknowName.._AnyFile.anyExtension
Etc
What I know is that there is only 2 levels but the names of the subfolders, the subsubfolders, the files, and their extensions could be anything.

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.

Why are the contents of the subfolders when MQFTE is used for transfer?

Hi when I tried to transfer the contents of a folder ( The folder has several subfolders and few files) using MQFTE ftecreatetransfer command, Not only the few files in the folder but also the contents of the subfolder are transferred to destination. The same subfolders are created in destination and the contents are transferred. Is there a way to avoid the files from subfolders being transferred ?
As per this page in the Infocenter:
When a directory is specified as a source file specification, the
contents of the directory are copied. More precisely, all files in the
directory and in all its subdirectories, including hidden files, are
copied.
However, it looks like they anticipated your question because the page recently added this clarification:
For example, to copy the contents of DIR1 to DIR2 only, specify
fteCreateTransfer ... -dd DIR2 DIR1/*
So instead of specifying the folder, add the wild card to the end and you get just the files in the top level of that folder. (Assuming of course that you do not also use the -r option!)

Resources