How do I untar multiple files within each tar files, exclusively in the Linux shell? - shellcode

I'm trying to untar a tarball of files and the shellcode will not work properly, the directory of the tarball is /problems/like1000_0_369bbdba2af17750ddf10cc415672f1c and my user is publicVoid#pico-2019-shell1: . There are about 1000 tar files and I need to get to the last one, any help would be appreciated as I am a beginner in this.
#! /bin/sh
for f in 1000.tar
do
tar xf "$f" -C publicVoid#pico-2019-shell1:/problems/like1000_0_369bbdba2af17750ddf10cc415672f1c
done
This is the error
publicVoid#pico-2019-shell1:~/bin$ ./tarScrip
tar: 1000.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
publicVoid#pico-2019-shell1:~/bin$

I'm working on the same thing too but it seems like you cant. the best bet is to try and untar it using a program that will allow it to. the tr file is a file containing may backups so there is a chance that the 1000 tar might cause a lot of lag due to the size. I am a beginner at shellcode but I have been somewhat successful at the shell. I do this for fun but I wish you good luck and may u win the cash

Related

tar: Cowardly refusing to create an empty archive

I use the following tar command to try to backup my entire file system
tar -cvpzf test/backup.tar.gz --exclude=/test
And I receive the following error message
tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.
Can somebody point me in the right direction as to how to use tar and explain why it's trying to create an empty archive?
You defined what to exclude, but didn't define what you actually want in the archive. Supply at least one path. If you want entire filesystem, then tar -c....... /

How to use quotes in bash scrips when a command in the script needs quotes too?

I am attempting to make a script that will make a backup file of a video file in the same directory with the time stamp at the end of the tar file. The script is for demonstration purposes only, that is why I do not intend on sending the file to a different directory. Below is how far I have come with it.
#!/bin/bash
cd Compression_Play/
echo Me.$(date +%d_%b_%Y-%k:%M:%S).tar.xz
tar -I "pixz -9t" -cvf Me.$(date +%d_%b_%Y-%k:%M:%S).tar.xz 2017-03-23_01-13-02.avi
My problem is whenever I try to execute the script it gives me this:
Me.29_Mar_2017-22:03:49.tar.xz
tar: -9: (PROGRAM ERROR) Option should have been recognized!?
Try 'tar --help' or 'tar --usage' for more information.
As best as I can tell the problem is with the quotes in my tar command. Is there a way to make the script so I can keep the quotes or substitute them?
Given your goal to make an archive, presumably preserving owner, file modes, file flags and ACLs, if available, then this should do what you need:
#!/bin/bash
archive_name="Me.$(date +%d_%b_%Y-%k:%M:%S).tar.xz"
$(cd Compression_Play/
tar -cvp 2017-03-23_01-13-02.avi |
pixz -9t > $archive_name
)
Based on the GitHub page for tarball compress/decompress for pixz, you will need to reverse the pipe to get your data out:
pixz -x9T < $archive_name | tar xvpf -
Greg gave a good answer and it works very well. I also figured out another way after nocking my head on it for several hours and taking the things from the help I got.
#!/bin/bash
cd /home/apowell/Compression_Play/Test_Backup
tar -I 'pixz -9t' -cvf Me.$(date +%d_%b_%Y-%H_%M_%S).tar.xz /home/apowell/Compression_Play/Linux_Programs
and this one compresses a little more by replacing pixz with just plain xz.
#!/bin/bash
cd /home/apowell/Compression_Play/Test_Backup
tar -I 'xz -9ve -T8 -k' -cvf Me.$(date +%d_%b_%Y-%H_%M_%S).tar.xz /home/apowell/Compression_Play/Linux_Programs

Extraction of selected/specific files from tar archive results in different behavior on SunOS and Linux

I hope this fits the category "programming question".
I have a tar-archive containing the folowing structure:
Folder1/File1
Folder2/File2
Folder3/File3
Folder4/File4
My goal is to extract specific contents from this archive (which is huge and therefore called hugeArchive.tar) in the following.
The data to extract is automatically generated and given to me via textfile "filesToExtract.txt".
Content of "filesToExtract.txt":
Folder1
Folder1/File1
Folder2
Folder2/File2
So I thought this task should be easy and I will do achieve it using
cat filesToExtract.txt | xargs tar -xvf hugeArchive.tar
On SunOS 5.10 this performes as expected but on Linux Redhat 6.8 I receive errors (though the general extraction still seems to work because the files are available afterwards)
Output SunOS 5.10:
x Folder1, 0 bytes, 0 tape blocks
x Folder1/File1, 386 bytes, 1 tape blocks
x Folder2, 0 bytes, 0 tape blocks
x Folder2/File2, 858 bytes, 2 tape blocks
Output on Linux Redhat 6.8:
Folder1/
Folder1/File1
Folder2/
Folder2/File2
tar: Folder1/File1: Not found in archive
tar: Folder2/File2: Not found in archive
tar: Exiting with failure status due to previous errors
I have no idea what is causing that so I played around and manually changed the input file filesToExtract.txt to look like this instead:
Folder1/File1
Folder2/File2
Now it works on Linux, witout any error messages. This made me wonder:
Maybe this is an overwriting problem? Or maybe the tar tool somehow only allows accessing each file only one time?
I created another kind of test and changed filesToExtract.txt again and included a duplicate there:
Folder1/File1
Folder2/File2
Folder1/File1
...and there we have the identical error from the first attempt again:
Folder1/File1
Folder2/File2
tar: Folder1/File1: Not found in archive
tar: Exiting with failure status due to previous errors
I am clueless what is behind it (acutally tar should overwrite without complaining, shouldn' it?). Do you have any idea? Is my command wrong? What will I have to change, that it works on Linux without having to change the filesToExtract.txt.
By the way I am using the standard tar implementation on both systems.
Thanks a lot in advance!
EDIT:
tripleee suggested to rather use
xargs tar -xvf hugeArchive.tar <filesToExtract.txt
since this is a command using redirection. But this is only for the sake of clearness/effectivity and won't affect the overall problematic behaviour
I might be wrong, but it seems that there is no satisfying answer.
If I do a "manual" apporach on Linux RH 6.8 this will happen:
Test 1:
tar -xvf myHugeArchive.tar Folder1
This extracts Folder1 with its content (File 1). I can repeat that command as often as I want without needing to delete the extracted data (so tar -xvf does indeed overwrite, just as it is supposed to to).
Test 2:
tar -xvf myHugeArchive.tar Folder1/File1
This also works and creates the Folder1 and extracts File 1.
I also can repeat this command as often as I want.
Test 3:
tar -xvf myHugeArchive.tar Folder1 Folder1/File1
This extracts the folder and the file, yes, but the process nevertheless fails (as expected) with the error depicted in the question.
Conclusion:
It dosn't work with GNU-tar that way (except there is a secret option parameter I don't know about...). In the end it seems like I have to preprocess and remove those "kind-of-duplicates" my filesToExtract.txt first.

Need help on the tar command

Have got a problem executing the command as below:
tar -xvf arch.tar.gz -s '/^bundle//'
Could be the
-s '/^bundle//'
is a problem as I've got errors like:
$ tar -xvf arch.tar.gz -s '/^bundle//'
tar: /^bundle: Not found in archive
tar: Exiting with failure status due to previous errors
The tried to run the command under Cygwin/Win10.
It's part of the longer script but I'm not sure what was the idea of original author. Archive does include the 'bundle' folder inside... and it's the only first level file there.
Thank you in advance :)
-s does not mean to do a substitution, which seems to be how you're trying to use it. You probably want --xform='s/^bundle//'
-s has the following entry in the help listing:
-s, --preserve-order, --same-order
member arguments are listed in the same order as
the files in the archive
With your code it's actually trying to find a file with the name /^bundle// which does not exist, even if bundle does. Also, the --xform option I gave will rewrite the names of files to strip the string bundle from the front. If you are just trying to not extract the file bundle you would want the flag --exclude='bundle'
In this case, if bundle is a top level directory in the archive, and it's the only one, you could also use the flag --strip-components=1, though this would get rid of all the top level directories, so might not be exactly what you want depending on your archive
Thanks all,
Problem solved other, then 'tar', way but for those who may be interested here is the answer I have found on the web:
If you are developing on Linux, or using GNU tar, this command should work:
tar -xvf arch.tar.gz --transform 's|^bundle/||'
For Mac or BSD-based operating systems:
tar -xvf arch.tar.gz -s '/^bundle//'
Yes, the idea was to remove the /bundle/ folder from files paths.

tar files using the -C option and wildcard

I'm passing a tar command to shell executor in an application. But it seems that my tar syntax is incorrect. (This is Windows (bsdtar command) but works the same as Linux as far as I know; I can also test on Linux if need be.)
I'm trying to tar gz everything up all files ending in ext without storing the full path in my tar file.
tar -cvzf test.tar.gz -C C:/mydir/toTar/ *.ext
I get an error:
tar: *.ext: Cannot stat: No such file or directory
I can give the whole path but then my tar will contain C->mydir->toTar->. I just want the files, not mydir and toTar in the result.
So far only thing that is close to what I want is . instead of *.ext, but that tars other things too, which I obviously don't want.
The problem is that * is a wildcard character that is expanded by the shell, but you are bypassing the shell and calling tar directly. The tar command is looking for one file which is named literally *.ext and it does not exist.
Your options are:
Expand the list of files in your own code and pass that list to tar.
Call the shell from your code by calling something like /bin/sh -c tar ...
With option 2 there may be security implications -- if the shell sees something it thinks is a command, it will run it. Option 1 is therefore safer, but it's up to you which makes more sense.
I am befuddled by how you're using dos-style paths in an apparently linux-like context. But this is how I'd do it. Hopefully the concept is clear if the details may be incorrect.
cd C:/mydir/toTar/
mkdir ~/tmpwork
find . -name '*.ext' > ~/tmpwork/extfiles
tar czvfT ~/tmpwork/test.tar.gz ~/tmpwork/extfiles
rm ~/tmpfiles/extfiles
There is no way around the shell expansion without using pipes, etc.

Resources