Extract tar file without creating folder - unix

I want to extract tar file in Unix tar xvf /home/test/group.tar and once extracted got a folder group which has list of xls,pdf,txt files.
How can i extract contents of group.tar inside /home/test/list of xls, pdf files without creating group folder.
Any specific command available or have to follow with copy and move??
Thanks!

You may use the --strip-components 1 parameter.
tar xvf group.tar --strip-components 1

Related

Archiving multiple files in Unix using tar and gzip

I have the requirement to archive multiple files keeping the original files using tar and gzip. I cannot take risks with the files I have.
For example, the files to be archived are:
ls
1.doc
2.doc
3.doc
4.xls
5.xls
6.xls
The expected output:
ls
1.doc
2.doc
3.doc
4.xls
5.xls
6.xls
archive.tar.gz
Where archive.tar.gz file contains all the doc and xls files.
Did you try the command:
tar czf archive.tar.gz *.doc *.xls
Options here are:
c: Create
z: Gzip
f: Output file
To extract:
tar xzf archive.tar.gz
You can read the manual of the tar command for advanced options:
man tar

How to extract a .tar.gz file on UNIX

I have a file (reviews_dataset.tar.gz) that contains many files which contains data. I am required to extract the files in this archive and then perform some basic commands on the file. So far I have created a directory named (CW) and found a command tar zxvf fileNameHere.tgz but when I run this it of course cannot find my file as I have not "downloaded it" into my directory yet? How do I get this file into my directory so that I can then extract it? Sorry if this is poorly worded I am extremely new to this.
You must either run the command from the directory your file exists in, or provide a relative or absolute path to the file. Let's do the latter:
cd /home/jsmith
mkdir cw
cd cw
tar zxvf /home/jsmith/Downloads/fileNameHere.tgz
You should use the command with the options preceded by dash like this:
tar -zxvf filename.tar.gz
If you want to specify the directory to save all the files use -C:
tar -zxf filename.tar.gz -C /root/Desktop/folder

Change last modified time of untarred files

I am using below command to untar
tar -xvf <filename.tar>
I want to make sure extracted files' modified time is updated to current time.
GNU tar has an option for this:
-m, --touch
don't extract file modified time
With this option, extracted files have the time of extraction as their last-modified.
Anyways, I found an answer. I looped through all the files in the tar and used touch command to change the modified time.
tar -xvf <filename.tar>
for f in $(tar -tf <filename>.tar); do touch $f;done

How to unjar a jar when the directories are not present in the destination?

There is a jar : my.jar that contains
folder1/First.txt
folder2/Second.txt
I need to unjar this into another location where folder1 and folder2 are not present. Is there a way to create directories in a go while running jar -xvf...? Or is there a better way to zip and unzip such files?
Got a solution for this...
Used : tar instead of jar
tar -cvf my.tar folder1/* folder2/*
tar -xvf my.tar

Tar files in one location

At 10 A.M files are like below say in one of the location
A.log,B.log
Tar file should contain A.log and B.log. Tar file name should be like
archival_file__oror_datetimestamp.tar
At 11 A.M if files are like below
A.log,B.log,C.log
Now the tar file which is getting created now should not contain A.log and B.log it should contain C.log only
If I correctly guess the intention of your question you might want to do something like
# 10AM:
tar -cf /path/to/tarfile/archival_file__oror_10AM.tar /path/to/logfiles/*.log
# 11 AM
tar -N /path/to/tarfile/archival_file__oror_10AM.tar -cf /path/to/tarfile/archival_file__oror_11AM.tar /path/to/logfiles/*.log
The second command will only put files newer than archival_file__oror_10AM.tar into the new archive.

Resources