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
Related
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
Im trying to tar a folder with subdirectories but i want to exclude all folders with the name "log".
I have search and seen that the tar command have the option of --exclude the problem is that this option required to be specific folder not a dynamic one.
Is there any other way?
so far the command i have is:
tar czf ROOT/backup/servers/20150504.tar.gz ./servers --exclude=".*log.*"
If you want to exclude all folders with the name "log", probably using -X is more convenient. Here is an example:
$ find ./servers -type -d -name *log* > excludefiles
$ tar czf ROOT/backup/servers/20150504.tar.gz -X excludefiles ./servers
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
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.
I am looking for a Unix command which will create a tar of 10 files from a directory.
tar cf path_of_tar.tar $(ls | head -10)
Add options to ls to select the 10 you want.
The command you're looking for is: tar
How it's usually used:
$ tar cf file.tar file1 file2...
Well, depending on your needs...
$ tar cf tenfiles.tar file1 file2 file3 ... file10
That'll do it. You can check out the tar manpage ($ man tar) for further details on other options you might need. (Your question was a bit vague, so I can't be that much more specific.)
I would suggest trying:
man tar
This will show all the options available and usage information. A typical usage for creating a tar of files in a directory would look like this:
tar -cvf myfiles.tar ./mydirectory
where myfiles.tar is the name of the tar file you want to create, and mydirectory is the directory the files reside in.
tar -cvf name.tar /path/to/file1 /path/to/file2 /path/to/file3 ...
Can you define what files are they? Are they of a specific filename pattern? My reasoning is asking that you specified 10 files.
In general:
tar cvf tar_with_10_files.tar somefile_with_wildcards_or_pattern_matching