Tag Info

Hot answers tagged

10

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


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

tar stores relative paths. 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 /home/foo/bar by ...


9

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


7

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


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


7

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


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


5

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


5

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


5

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


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


4

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.


4

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


4

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


4

Using the usual command-line zip tool, I don't think you can avoid separate extraction and update commands. source_zip=$PWD/sourceZip.zip target_zip=$PWD/targetZip.zip temp_dir=$(mktemp -dt) ( cd "$temp_dir" unzip "$source_zip" zip -g "$targetZip" . # or if you want just the two files: zip -g "$targetZip" textFile.txt binFile.bin ) rm -rf "$temp_dir" ...


4

My suggestion would be to use a good old fashioned CD/DVD. Manually installing all packages with dpkg is possible if you download each .deb along with its dependacies (and theirs, and theirs...) but really not pleasant. I would: download and burn the CD/DVD of the Debian distro you are using (check /etc/debian_version) if you dont have one Put the DVD in ...


4

You asked if it's possible: yes, this is possible if you mount the zip as a filesystem (or, of course, if you unzip the archive, which I'm assuming you're explicitly not willing to do from Some Good Reason). See Fuse-Zip for a tool that will do this. You could then do something like: $ mkdir foo ; fuse-zip foo.zip foo $ foo/running-my-script-in-foozip.sh ...


4

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


4

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


4

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


3

Simple answer - yes, it can pose security risks - but these are entirely dependent on the specific access control requirements for the files and directories involved. Your best bet is to ask the application owner/developer/etc whether there are any files or directories which require permissions to be enforced as well as whether there are any which need to ...


3

$ zip -r dir1 dir1 -x dir1/dir3/* works for me. Here -x is the exclude option. You could also use an include option, but in this case, the exclude option involves less typing. Actually the question is not completely clear. Do you want all directories and files under dir3 excluded as well, or just the files under dir3? The command above only works for the ...


3

You can flatted the entire contents of the zip file using cd /yours && unzip -j /path/to/mine.zip. The -j option is called "junk paths" and just dumps each file into the current directory instead of extracting any directory structure. To be more exactly than that, i.e. extracting directory structures except for the top one, you will need to know the ...


3

from the wget man page: --no-use-server-timestamps Don't set the local file's timestamp by the one on the server. By default, when a file is downloaded, it's timestamps are set to match those from the remote file. This allows the use of --timestamping on subsequent invocations of wget. However, it is ...


3

You can use the gzrt (gz repair tool) to unzip whatever part of the dd file remains. You can then type gzrecover sheeva-mem.dd.gz and attempt to mount the dd file: mount sheeva-mem.dd /mnt/image -o loop Possibly, the filesystem will be corrupted. You can attempt to repair it with fsck.


3

If always there are two, is simple: for f in file+([0-9]).png; do zip "${f%png}zip" "$f" "${f/./@2x.}"; done Note that the above will work as is from the command line. If you intend to use it in a script, put shopt -s extglob somewhere before that line. (extglob is enabled by default only in interactive shells.) In old bash not handling extended patterns ...


2

One method to work with archive files is to mount them, and then access them like normal directories. FUSE is available for most unices and supports several filesystems to access compressed files transparently. For zip files, possibilities include fuse-zip (AVFS is also convenient but read-only). For example, with fuse-zip, here's how to mount the archive ...


2

I once needed something similar to find class files in a bunch of zip files. Here it is: #!/bin/bash function process() { while read line; do if [[ "$line" =~ ^Archive:\s*(.*) ]] ; then ar="${BASH_REMATCH[1]}" #echo "$ar" else if [[ "$line" =~ \s*([^ ]*abc\.jpg)$ ]] ; then echo "${ar}: ${BASH_REMATCH[1]}" ...


2

There isn't any direct security risk with making a file executable unless it's setuid or setgid. Of course, there's the indirect risk that something you expect to be inert — some data file that you'd normally open in an application — can also be executed directly on your system with nefarious consequences. For example, if you have a file called README that ...



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