Difference between two .tar.gz file lists on linux
Just list the contents and do diff
:
diff <(tar -tvf 1.tar.gz | sort) <(tar -tvf 2.tar.gz | sort)
How to get diff between two tar.gz
This also works:
$ diff <(tar -tvf 1.tar.gz | rev | cut -d\/ -f1 | rev) <(tar -tvf 2.tar.gz | rev | cut -d\/ -f1 | rev)
1a2
> helloworld.txt.gpg
Further explanation:
The following: | rev | cur -d\/ -f1 | rev
is a quick way of getting just the filename out of a full path.
How to compare two tarball's content
tarsum is almost what you need. Take its output, run it through sort to get the ordering identical on each, and then compare the two with diff. That should get you a basic implementation going, and it would be easily enough to pull those steps into the main program by modifying the Python code to do the whole job.
How can I compare two zip format(.tar,.gz,.Z) files in Unix
exact answer i want is this only
nawk -F"," 'NR==FNR {a[$1];next} ($3 in a)' <(gzcat file1.txt.gz) <(gzcat file2.txt.gz)
. instead of awk, nawk works perfectly and it's gzip file so use gzcat
Why do the md5 hashes of two tarballs of the same file differ?
tar czf outfile infiles
is equivalent to
tar cf - infiles | gzip > outfile
The reason the files are different is because gzip
puts its input filename and modification time into the compressed file. When the input is a pipe, it uses an empty string as the filename and the current time as the modification time.
But it also has a --no-name
option, which tells it not to put the name and timestamp into the file. So if you write the expanded command explicitly, instead of using the -z
option to tar
, you can make use of this option.
tar cf - testfile | gzip --no-name > a.tar.gz
tar cf - testfile | gzip --no-name > b.tar.gz
I tested this on OS X 10.6.8 and it works.
How to list the folders/files of a file.tar.gz file inside a file.tar
You may want to use and condition:
tar -xf abc.tar "abc.tar.gz" && tar -ztvf abc.tar.gz
Explanation:
For listing of files we use
If file is of type tar.gz:
tar -ztvf file.tar.gz
If file is of type tar:
tar -tvf file.tar
If file is of type tar.bz2:
tar -jtvf file.tar.bz2
You can also search for files in any of the above commands. e.g:
tar -tvf file.tar.bz2 '*.txt'
For extracting files we use
tar -xf file.tar
In these commands,
- t: List the contents of an archive.
- v: Verbosely list files processed (display detailed information).
- z: Filter the archive through gzip so that we can open compressed
(decompress) .gz tar file. - j: Filter archive through bzip2, use to decompress .bz2 files.
- f filename: Use archive file called filename.
- x: Extract all files from given tar, but when passed with a filename
will extract only matching files
Compare Folders, Create Archive of Differences
This line excludes files that are only in one or the other, but creates the tar.gz file that you want.
diff -rq folderA folderB | grep -v "^Only in" | sed "s/^.*and folderB/folderB/g" | sed "s/ differ//g" | tar czf output.tar.gz -T -
Broken down it goes:
dif -rq folderA folderB
Do a recursive diff between these folders, be quiet about it - only output the file names.
| grep -v "^Only in"
Exclude output lines that indicate one file is only in one of the folders. I'm assuming from your description this isn't an issue for you, but the two folders I was playing with were a bit dirty.
| sed "s/^.*and folderB/folderB/g"
Discard the first bit of the output up until it says " and " and then the name of the second folder. This actually takes away the second folder name as well, but then replaces it back in
| sed "s/ differ//g"
Discard the end bit of the diff output.
| tar czf output.tar.gz -T -
Tell tar to do the thing. c
== create a tar file z
means compress it (zip) f
means the filename is coming shortly. output.tar.gz
is your output file -T
means "get the filenames from the file I'm about to tell you" the final -
means "use stdin instead"
I suggest you build this up yourself in the individual steps so you can see how it is constructed, and what the output of each step is like.
Related Topics
Shell-Init: Error Retrieving Current Directory: Getcwd -- the Usual Fixes Do Not Wor
Given a Linux Username and a Password How to Test If It Is a Valid Account
Logo Programming Language Implementations
List of Possible Internal Socket Statuses from /Proc
Is There Any Method to Run Perf Under Wsl
Detecting a Chroot Jail from Within
How to Change the Monitor Brightness on Linux
How to Use Linux 'Perf' Tool to Generate "Off-Cpu" Profile
Redirecting Output of Bash for Loop
How to Define a Bash Alias as a Sequence of Multiple Commands
How to Run R Scripts on Servers Without X11
Differencebetween .Got and .Got.Plt Section
How to Execute an Local Script in Remote Server with Parameters
After Changing /Etc/Profile, What Do I Have to Do to Reset My Shell
What's the Difference of Redirect an Output Using ">", "&>", ">&" and "2&>"