tar

python: use CSV reader with single file extracted from tarfile

寵の児 提交于 2020-04-16 05:49:41
问题 I am trying to use the Python CSV reader to read a CSV file that I extract from a .tar.gz file using Python's tarfile library. I have this: tarFile = tarfile.open(name=tarFileName, mode="r") for file in tarFile.getmembers(): tarredCSV = tarFile.extractfile(file) reader = csv.reader(tarredCSV) next(reader) # skip header for row in reader: if row[3] not in CSVRows.values(): CSVRows[row[3]] = row All the files in the tar file are all CSVs. I am getting an exception on the first file. I am

python: use CSV reader with single file extracted from tarfile

元气小坏坏 提交于 2020-04-16 05:49:11
问题 I am trying to use the Python CSV reader to read a CSV file that I extract from a .tar.gz file using Python's tarfile library. I have this: tarFile = tarfile.open(name=tarFileName, mode="r") for file in tarFile.getmembers(): tarredCSV = tarFile.extractfile(file) reader = csv.reader(tarredCSV) next(reader) # skip header for row in reader: if row[3] not in CSVRows.values(): CSVRows[row[3]] = row All the files in the tar file are all CSVs. I am getting an exception on the first file. I am

Extracting specific files with file extension from a .tar.xz archive using MacOS terminal

半城伤御伤魂 提交于 2020-04-16 04:06:45
问题 I have a number of compressed archives with the extension .tar.xz . I am advised that, when decompressed, the total size required is around 2TB. Within the archives are a number of images that I am solely after. Is there a method to solely extract files for example with the extensions .jpeg, .jpeg and .gif from the compressed archives without having to extract every file? Thanks 回答1: It's trivial to just extract one of the file types; for example: tar -xjf archive.tar.xz '*.jpeg' will extract

Extracting specific files with file extension from a .tar.xz archive using MacOS terminal

纵然是瞬间 提交于 2020-04-16 04:05:53
问题 I have a number of compressed archives with the extension .tar.xz . I am advised that, when decompressed, the total size required is around 2TB. Within the archives are a number of images that I am solely after. Is there a method to solely extract files for example with the extensions .jpeg, .jpeg and .gif from the compressed archives without having to extract every file? Thanks 回答1: It's trivial to just extract one of the file types; for example: tar -xjf archive.tar.xz '*.jpeg' will extract

Extracting specific files with file extension from a .tar.xz archive using MacOS terminal

巧了我就是萌 提交于 2020-04-16 04:05:22
问题 I have a number of compressed archives with the extension .tar.xz . I am advised that, when decompressed, the total size required is around 2TB. Within the archives are a number of images that I am solely after. Is there a method to solely extract files for example with the extensions .jpeg, .jpeg and .gif from the compressed archives without having to extract every file? Thanks 回答1: It's trivial to just extract one of the file types; for example: tar -xjf archive.tar.xz '*.jpeg' will extract

How to create an empty tgz file?

人走茶凉 提交于 2020-04-13 06:57:28
问题 How to create an empty tgz file? I tried tar czvf /tmp/empty.tgz --from-file /dev/null tar: Option --from-file is not supported 回答1: The switch you're looking for is --files-from or -T : tar czvf /tmp/empty.tgz --files-from=/dev/null 来源: https://stackoverflow.com/questions/44807644/how-to-create-an-empty-tgz-file

tar 命令

好久不见. 提交于 2020-04-08 13:55:14
tar 命令的常用参数 -c :创建打包文件,可搭配 -v 来查看过程中被打包的文件名; -t :查看打包文件的内容含有哪些文件名,重点在查看“文件名”; -x :解压缩功能,可以搭配 -C (大写) 在特定目录解开 特别留意的是, -c, -t, -x 不可同时出现在一串命令行中。 -z :通过 gzip 的支持进行压缩/解压缩:此时文件名最好为 *.tar.gz -j :通过 bzip2 的支持进行压缩/解压缩:此时文件名最好为 *.tar.bz2 -J :通过 xz 的支持进行压缩/解压缩:此时文件名最好为 *.tar.xz 特别留意, -z, -j, -J 不可以同时出现在一串命令行中 -v :在压缩/解压缩的过程中,将正在处理的文件名显示出来! -f filename:-f 后面要立刻接要被处理的文件名! -C 目录 :这个选项用在解压缩,若要在特定目录解压缩,可以使用这个选项。 -p(小写) :保留备份数据的原本权限与属性,常用于备份(-c)重要的配置文件 -P(大写) :保留绝对路径,亦即允许备份数据中含有根目录存在之意; tar 命令的使用案例: tar -czvf 命令打包/etc/目录下的所有文件,包括递归目录 tar xf 解压tar.gz格式tar包并且使用-C选项指定解压的路径 tar -tvf 命令查看tar包文件中的内容 来源: 51CTO 作者:

Linux基础知识三-基本命令2

隐身守侯 提交于 2020-04-08 13:03:55
1.帮助命令 1.1 man 命令名 (manual缩写为man) 获取指定命令的帮助:命令是做什么的?如何用?(命令的选项) 注意:man 帮助有不同级别 1.1.1如何获知命令的帮助存在哪些级别? man -f 命令名 whereis 命令名 ——也可以看到命令存在哪些级别的帮助 1.1.2查询命令不同级别的帮助 先通过man -f 命令名,查询到命令有哪些级别; 再根据man man 查询到不同级别的含义; 最后,查看需要级别的帮助:man -5 passwd,man -4 null,man -8 ifconfig 注意:如果命令有多个等级帮助,则默认打开的是最小等级的帮助! 1.1.3 查看和命令相关的所有帮助 man -k 命令名 相当于 apropos 命令名 1.2 help 命令 1.2.1 用法:命令名 --help 获取命令选项的帮助 ,如: ls --help 1.2.2 shell 内部命令帮助 shell:命令行解释器,Linux中用户与Linux交互的接口! 用法: help shell内部命令 获取shell内部命令的帮助,如:help cd 注意: 如何区分是不是shell 内部命令? 通过whereis 命令 查询是否有命令的可执行文件,如果有,则不是shell的内部命令,否则就是内部命令。 1.2.3 info命令 用法: info 命令名 注意

归档管理:tar

我是研究僧i 提交于 2020-04-07 12:21:58
计算机中的数据经常需要备份,tar是Unix/Linux中最常⽤的备份⼯具,此命令可以把⼀系列⽂件归档到⼀个⼤⽂件中,也可以把档案⽂件解开以恢复数据。 tar使⽤格式 tar [参数] 打包⽂件名 ⽂件 tar命令很特殊,其参数前⾯可以使⽤“-”,也可以不使⽤。 常⽤参数: 参数 含义 -c   ⽣成档案⽂件,创建打包⽂件 -v    列出归档解档的详细过程,显示进度 -f     指定档案⽂件名称,f后⾯⼀定是.tar⽂件,所以必须放选项最后 -t     列出档案中包含的⽂件 -x    解开档案⽂件 注意:除了f需要放在参数的最后,其它参数的顺序任意 另外: 若文件是以XXXXX.tar.gz结尾的,则用tar -xvf 进行解压缩 若文件是以XXXXX.gz结尾的,则使用gzip -d进行解压缩 来源: https://www.cnblogs.com/otways/p/11579934.html

Read .tar.gz file in Python

天涯浪子 提交于 2020-04-06 02:10:10
问题 I have a text file of 25GB. so i compressed it to tar.gz and it became 450 MB. now i want to read that file from python and process the text data.for this i referred question . but in my case code doesn't work. the code is as follows : import tarfile import numpy as np tar = tarfile.open("filename.tar.gz", "r:gz") for member in tar.getmembers(): f=tar.extractfile(member) content = f.read() Data = np.loadtxt(content) the error is as follows : Traceback (most recent call last): File