Tag Info

Hot answers tagged

154

No. Unlike zip, gzip functions as a compression algorithm only. Because of various reasons some of which hearken back to the era of tape drives, Unix uses a program named tar to archive data, which can then be compressed with a compression program like gzip, bzip2, 7zip, etc. In order to "zip" a directory, the correct command would be tar -zcvf ...


60

Typically one uses tar to create an uncompressed archive and either gzip or bzip2 to compress that archive. The corresponding gunzip and bunzip2 commands can be used to uncompress said archive, or you can just use flags on the tar command to perform the uncompression. If you are referring specifically to the Zip file format, you can simply use the zip and ...


48

You can just use *; there is no need for *.*. File extensions are not special on Unix. * matches zero or more characters—including a dot. So it matches foo.png, because that's zero or more characters (seven, to be exact). Note that * by default doesn't match files beginning with a dot (neither does *.*). This is often what you want. If not, in bash, if you ...


33

unzip -j "myarchive.zip" "in/archive/file.txt" -d "/path/to/unzip/to" Enter full path for zipped file, not just the filename. Be sure to keep the structure as seen from within the zip file. This will extract the single file file.txt in myarchive.zip to /path/to/unzip/to/file.txt.


32

tar stores relative paths by default. GNU tar even says so if you try to store an absolute path: tar -cf foo.tar /home/foo tar: Removing leading `/' from member names If you need to extract a particular folder, have a look at what's in the tar file: tar -tvf foo.tar And note the exact filename. In the case of my foo.tar file, I could extract ...


28

You can extract just the text to standard output with the -p option: unzip -p myarchive.zip path/to/zipped/file.txt >file.txt This won't extract the metadata (date, permissions, …), only the file contents. That's the price to pay for the convenience of not having to move the file afterwards. Alternatively, mount the archive as a directory and just ...


26

You can use this loop in bash: for i in */; do zip -r "${i%/}.zip" "$i"; done i is the name of the loop variable. */ means every subdirectory of the current directory, and will include a trailing slash in those names. Make sure you cd to the right place before executing this. "$i" simply names that directory, including trailing slash. The quotation marks ...


22

Install zip and use zip -r foo.zip . You can use the flags -0 (none) to -9 (best) to change compressionrate Excluding files can be done via the -x flag. From the man-page: -x files --exclude files Explicitly exclude the specified files, as in: zip -r foo foo -x \*.o which will include the contents of foo in ...


18

You will need to join them first. You may use the common linux app, cat as in the example below: cat test.zip* > ~/test.zip This will concatenate all of your test.zip.001, test.zip.002, etc files into one larger, test.zip file. Once you have that single file, you may run unzip test.zip "How to create, split, join and extract zip archives in Linux" ...


17

The Linux unzip utility doesn't really support multipart zips. From the manual: Multi-part archives are not yet supported, except in conjunction with zip. (All parts must be concatenated together in order, and then zip -F (for zip 2.x) or zip -FF (for zip 3.x) must be performed on the concatenated archive in order to ...


17

You can use the command archivemount to mount archives such as .tar.gz. $ ls files.tgz mnt/ $ archivemount files.tgz mnt $ ls mnt file1 file2 [... Perform desired read/write operations on the archive via mnt/ ...] $ umount mnt [... Any changes are saved to the archive ...] See the man page for archivemount for more info. It's often times not ...


16

Try: unzip "/path/to/archive.zip" "in/archive/folder/\*" -d "/path/to/unzip/to"


13

The gzip command will not recursively compress a directory into a single zip file, when using the -r switch. Rather it will walk that directory structure and zip each file that it finds into a separate file. Example before $ tree dir1/ dir1/ |-- dir11 | |-- file11 | |-- file12 | `-- file13 |-- file1 |-- file2 `-- file3 now run the gzip command $ ...


12

0040000 is the traditional value of S_IFDIR, the file type flag representing a directory. The type uses the top 4 bits of the 16-bit st_mode value, 0100000 is the value for regular files. The high 16 bits of the external file attributes seem to be used for OS-specific permissions. The Unix values are the same as on traditional unix implementations. Other ...


11

Ok, let's apply the unix philosophy. What are the components of this task? Text search: you need a tool to search text in a file, such as grep. Recursive: you need a tool to go looking for files in a directory tree, such as find. Archives: you need a tool to read them. Most unix programs operate on files. So to operate easily on archive components, you ...


11

Well, when it comes to distributing files for a variety of operating systems, I'd recommend 7-zip. Usually in the package p7zip, you'll get the 7z and 7za command, with which you can create your own 7z archives. 7za can also decompress standard (pkzip) zip archives (and create them as well with the -tzip switch). Compressing: 7za a archive.7z file1 file2 ...


11

You can list the content of the archive and then pass the list to rm using xargs Example for a tarball (test it without the rm first): tar tfz archive.tar.gz | xargs rm -rf


11

You can try to find the relevant files with find: find /usr/something -maxdepth 1 -user antoine You can then use -exec to create a zip file from the results of find: find /usr/something -maxdepth 1 -user antoine -exec zip /tmp/file.zip {} + leave out the maxdepth if you want to recurse.


10

You can zip files up with: tar -zcvf myfile.tgz . which will do the current directory. Replace . with other file names if you want something else. To unzip that file, use: tar -zxvf myfile.tgz That's assuming of course that you have a tar capable of doing the compression as well as combining of files into one. If not, you can just use tar cvf ...


10

By name You can generate the list of files in the archive and delete them, though this is annoyingly fiddly with archivers such as unzip or 7z that don't have an option to generate a plain list of file names. Even with tar, this assumes there are no newlines in file names. tar tf foo.tar | while read -r file; do rm -- "$file" done unzip -l foo.zip | awk ' ...


9

You can use the unzip utility with the -v flag: unzip -v files.zip Archive: files.zip Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 0 Stored 0 0% 11-23-2011 15:02 00000000 file1 0 Stored 0 0% 11-23-2011 15:02 00000000 file2 -------- ...


9

The general way for doing things like this is to prefix the file name with ./. zip foo.zip ./-foo This technique works most other utilities which accept a file name as an argument.


9

You can use GNU parallel to do that as it can limit the number of elements to a job as well as provide a job number (for a unique zip archive name): $ touch $(seq 20) $ find . ! -name "*.zip" -type f -print0 | parallel -0 -N 5 zip arch{#} {} adding: 1 (stored 0%) adding: 10 (stored 0%) adding: 11 (stored 0%) adding: 12 (stored 0%) adding: 13 ...


8

You're either talking about a FUSE filesystem (filesystem in userspace - Linus calls them toys) or a custom compiled kernel OR squashfs. Squash is not exactly as you describe - you cannot simply mount a tarball for instance - not with the kernel supported VFS, anyway - but you can certainly mksquash any number of files or directories and mount the resulting ...


8

You're looking for zipsplit, it does pretty much what you're asking for. You'd create a ZIP file containing all your files, and then split it into files according to your requirements with zipsplit. Something like: zip -9 myfile.zip * zipsplit -n 250000000 myfile.zip would produce myfile1.zip, myfile2.zip etc., all independent of each other, and none ...


7

I'm probably misunderstanding you, but you just specify the paths one after the other: zip foo.zip /path/to/first/file /path/to/second/file


7

It is in general not possible to search for content within a compressed file without uncompressing it one way or another. Since zipgrep is only a shellscript, wrapping unzip and egrep itself, you might just as well do it manually: for file in *.zip; do unzip -c "$file" | grep "ORA-1680"; done If you need just the list of matching zip files, you can use ...


7

Try: for f in `ls *.zip`; do echo "$f: "; unzip -l $f | grep <file_name>; done


7

My version of unzip has a -j option to not create any directory. So unzip -j /path/to/file.zip Will extract all the files into the current directory without restoring the directory structure stored in the zip file.


7

The UNIX philosophy is to have small tools. One tool is doing exactly one thing, but this especially well. The tar tool is just combining several files into a single file without any compression. The gzip tool is just compressing a single file. If you want to have both, you just combine both tools resulting in a .tar.gz file. The zip tool is a ...



Only top voted, non community-wiki answers of a minimum length are eligible