Tag Info

Hot answers tagged

29

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 ...


20

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 ...


16

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.


15

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 ...


11

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 ...


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

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 ...


10

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 ...


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 ' ...


10

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 ...


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.


8

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 ...


8

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


8

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 ...


8

You will need to join them first, I think. Try something like: cat x* > ~/hugefile "How to create, split, join and extract zip archives in Linux" may help.


7

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 ...


7

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 -------- ...


6

It's not pretty or elegant, but adding the executable bit to a file that isn't any kind of executable the OS knows what to do with isn't harmful -- if you try you'll likely just get cannot execute binary file One potential risk would be text files if somehow the first few words turn out to be valid commands in the shell, but that's hard to predict (if ...


6

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


6

Yes, you can use nullglob in bash: $ shopt -s nullglob $ tee foo.zip bar.zip </dev/null $ echo *.zip *.jar bar.zip foo.zip The nullglob option changes the behaviour of a non-matching glob from becoming a literal string to being removed entirely. However, this will likely not suffice in your particular use case, as unzip won't know what to do if it is ...


6

Edit: OK. Notice question has been updated so this You do not get a v0.1 but v1.0. does not longer apply. The version is not "how capable" the file is but what minimum version is required to extract that file from within the archive. This is not the overall version for the archive! One difference here is that e.g. OO tags all files with same version ...


6

Try: zip foo.zip -- -foo Simply put -- before the filename(s).


5

Doesn't unzip -l somefile.zip do exactly what you want?


5

I would do something like this (zsh syntax): unz() ( tmp=$(TMPDIR=. mktemp -d -- ${${argv[-1]:t:r}%.tar}.XXXXXX) || exit print -r >&2 "Extracting in $tmp" cd -- $tmp || exit [[ $argv[-1] = /* ]] || argv[-1]=../$argv[-1] (set -x; "$@"); ret=$? files=(*(ND[1,2])) case $#files in (0) print -r >&2 "No file created" rmdir ...


5

You can use bash scripting, but for compression etc. it relies on other programs. You might be better of with Python, or any other scripting language which can generate CSV files for you (although CSV syntax is not necessarily difficult to generate), and that can do the concatenation and compression. Given this directory of files (all different length, but ...


5

Try using -- For example: zip foo.zip -- -folder


5

With zsh: zip mine.zip ./*(.U) to zip my (regular) files. zip antoine.zip ./*(.u:antoine:) to zip antoine's


5

Using only features available on AIX or other POSIX-and-hardly-more systems: find /usr/something/* /usr/something/.[!.]* /usr/something/..?* \ -prune -type f -user antoine -exec zip -r /tmp/file.zip {} + find recurses into subdirectories. To avoid that, -prune tells it to not descend into the directories it encounters. That's no good if I run find ...


5

zip -r /path/to/save/destination_folder.zip /path/to/folder /path/to/folder - path to your source folder /path/to/save/destination_folder.zip - path to destination zip-file r - recurse into directories Also you can just type zip in putty command prompt to get help information Please, notice I wrote information for *nix systems. For Win it could ...


4

zip -0 ../backup/backup.zip -r . -x "*CVS*" "*Thumbs.db*" "*.svn*" -x also accepts a list of excludes. Alternatively, create a filelist with your excludes and add them there. The exclude.lst: *CVS* *Thumbs.db* *.svn* exclude.lst with the command: zip -0 ../backup/backup.zip -r . -x@exclude.lst



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