Hi I work with fedora 17 and I want to create zip file
There are four files in my directory /tmp/manager/
sos.prj
sos.shp
sos.shx
sbb.shh
I want to create zip file from sos.prj,sos.shp,sos.shx files
I want to use grep. In other words, I want to create zip file from grep's result
Can anybody help me?
zip myArchiveName *.{prj,shp,shx}
This will zip all files with your extensions listed into a zip file named myArchiveName.zip
People normally use tar and some archiver, examples:
tar czf manager.tar.gz /tmp/manager/
tar cjf manager.tar.bz2 /tmp/manager/
tar cJf manager.tar.xz /tmp/manager/
.xz format often yields the highest compression ratio and this is the compression format used for .rpm in Fedora.
Perhaps the OP was thinking of using grep to find all the sos.* files but as #Impossibear says it's easier to just use a wildcard. If you want to focus on sos files, you could use zip myArchive sos.*
Related
I want to download, decompress, and use a pretrained model from tensorflow-hub
After downloading I end up with a 1.tar.tar file, which I probably need to extract / decompress in order to be able to use it.
I can't wrap my head around how, I am working in a Linux terminal.
If your tar file is compressed using tar compression, use this command to decompress it. Make sure to be in the directory of the tar.tar file, it will decompress everything into the directory you are currently in.
$ tar xvzf 1.tar.tar
Where,
x: This option tells tar to extract the files.
v: The “v” stands for “verbose.” This option will list all of the files one by one in the archive.
z: The z option is very important and tells the tar command to uncompress the file.
f: This options tells tar that you are going to give it a file name to work with.
Nice to know:
A tarball is a group or archive of files that are bundled together using the tar command and have the .tar file extension.
I want to compress files from the filesystem to a directory within a new zip archive or update an old one. So here is my example:
directory/
|-file1.ext
|-file2.ext
|-file3.ext
in the zip archive it should look like this:
new_directory/
|-file1.ext
|-file2.ext
|-file3.ext
I could copy the files to a new directory and compress them from there but i do not want to have that extra step. I haven't found an answer to that problem on google. The man page doesn't mention anything like that aswell so I hope somebody can help me.
I don't think the zip utility supports this sort of transformation. A workaround is to use a symbolic link:
ln -s directory new_directory
zip -r foo.zip new_directory
rm new_directory
If other archive formats are an option for you, then this would be a bit easier with a tar archive, since GNU tar has a --transform option taking a sed command that it applies to the file name before adding the file to the archive.
In that case, you could use (for example)
tar czf foo.tar.gz --transform 's:^directory/:new_directory/:' directory
I've tried multiple ways of creating a zip or a tar.gz on the mac using GUI or command lines, and I have tried decompressing on the Linux side and gotten various errors, from things like "File.XML" and "File.xml" both appearing in a directory, to all sorts of others about something being truncated, etc.
Without listing all my experiments on the command line on the Mac and Linux (using tcsh), what should 2 bullet proof commands be to:
1) make a zip file of a directory (with no __MACOSX folders)
2) unzip / untar (whatever) the Mac zip on Linux with no errors (and no __MACOSX folders)
IT staff on the Linux side said they "usually use .gz and use gzip and gunzip commands".
Thanks!
After much research and experimentation, I found this works every time:
1) Create a zipped tar file with this command on the Mac in Terminal:
tar -cvzf your_archive_name.tar.gz your_folder_name/
2) When you FTP the file from one server to another, make sure you do so with binary mode turned on
3) Unzip and untar in two steps in your shell on the Linux box (in this case, tcsh):
gunzip your_archive_name.tar.gz
tar -xvf your_archive_name.tar
On my Mac and in ssh bash I use the following simple commands:
Create Zip File (-czf)
tar -czf NAME.tgz FOLDER
Extract Zip File (-xzf)
tar -xzf NAME.tgz
Best, Mike
First off, the File.XML and File.xml cannot both appear in an HFS+ file system. It is possible, but very unusual, for someone to format a case-sensitive HFSX file system that would permit that. Can you really create two such files and see them listed separately?
You can use the -X option with zip to prevent resource forks and extended attributes from being saved. You can also throw in a -x .DS_Store to get rid of those files as well.
For tar, precede it with COPYFILE_DISABLE=true or setenv COPYFILE_DISABLE true, depending on your shell. You can also throw in an --exclude=.DS_Store.
Your "IT Staff" gave you a pretty useless answer, since gzip can only compress one file. gzip has to be used in combination with tar to archive a directory.
so I did this
tar cvzf test.zip FP
with the intention of creating a zip of the directory FP
however, it instead lists the directories inside the zip
FP/
FP/php/
FP/php/pdf/
FP/php/docs/
FP/aspnet/
FP/aspnet/pdf/
FP/aspnet/docs/
how do I go about tarring the directory?
Your command is good indeed.
Listing appear when specifying v option (in 'cvzf')
You can check what a gzipped tar file contain by running
$ tar tzvf test.zip
By the way you should avoid to put .zip extension on a "gzipped" tar file. If you really want to make a zip, use 'zip' package instead.
I think it DID create it. The list is just the command being verbose (-v).
I have a backup of my site which is around 200GB(tar). I only want to extract a single file from this backup.
Any ideas on how I could go about doing this?
First you can execute this to get a list of all filenames:
tar tf archive.tar
Then using this command you can extract only the files you desire
tar xf archive.tar path/inside/archive/a.txt another/path/b.txt
Note that you may need to use z, j or another option depending on whether and what compression you've used.