tar directory contains ._ files - python-3.x

I extracted files from a tar directory and noticed that on my mac for each file there was also another file named ._<filename>. I did the standard procedure with:
import tarfile
with tarfile.open('file.tar.gz', 'r:gz') as tar:
tar.extractall()
The files contain something like:
Mac OS X 2PATTRP���Acom.apple.qua....
Can I get rid of those before extracting somehow? Or would I have to check if the file starts with ._ before doing so?

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]

7z x file.rar produces empty txt files

I want to extract a rar file on a server, where I don't have sudo rights. Unfortunately, no unrar is installed, but only 7zip. When I try to extract the rar file, that contains a bunch of txt files, via
7z x file.rar
the txt files are created, but they are all empty. I checked it locally and the rar file is not corrupted, so the problem lies somewhere else. I also receive the fellowing errors:
ERROR: Unsupported Method : extracted_file.txt
Sub items Errors: 153
Archives with Errors: 1
Does anyone know how to deal with that problem? Is there another way to extract the rar file potentially? I tried to write a python script, which uses the package rarfile, but it needs unrar to be installed.

Zip 500 files into one output file

I have 500 files and I want to zip into one file output file.
Input files:
abc.pdf
afa.pdf
dgh.pdf
sdg.pdf
....so on
Desired output file should be:
abc.zip
Or
sdg.zip
Or any starting name of input file.
just use the standard zip method for linux:
zip out.zip *.pdf
Assuming all your files are in the same directory, you could do this (run from the same directory):
zip abc.zip *.pdf

How to get the list of files (ls command) from bz2 archive?

What is the Unix bash command to get the list of files (like ls) from archive file of type .bz2 (without unzipping the archive)?
First bzip2, gzip, etc compress only one file. So probably you have compressed tar file. To list the files you need command like:
tar tjvf file.bz2
This command uncompress the archive and test the content of tar.
Note that bzip2 compresses each file, and a simple .bz2 file always contains a single file of the same name with the ".bz2" part stripped off. When using bzip2 to compress a file, there is no option to specify a different name, the original name is used and .bz2 appended. So there are no files, only 1 file. If that file is a tar archive, it can contain many files, and the whole contents of the .tar.bz2 file can be listed with "tar tf file.tar.bz2" without unpacking the archive.

How to tar all the files in the directory but not the directory itself

I want to tar all the files in the specified directory. But I don't want to get the directory tar'ed also not the sub-directories too. Currently I have this
>>> import tarfile
>>> with tarfile.open("x.gz","w:gz") as tar:
... tar.add("a", arcname=os.path.basename("a")) #a is the directory
But it is tar'ing the directory and sub-directories too.
I think you'll have to iterate over the contents of the directory and add each file in there one by one:
for elem in os.scandir('a'):
if elem.is_file:
tar.add(elem.path)

Resources