How can I force unzip / zip not to create a subdirectory when I extract it?
If your zip file contains no directory structure or you do not need to preserve it, you can use this:
cd /tmp
wget http://omeka.org/files/omeka-1.5.1.zip
unzip -j omeka-1.5.1.zip -d omeka
cd omeka
ll
Use a FUSE filesystem that allows you to browse archives like directories, such as AVFS. Use cp
to extract the files to the directory of your choice.
mountavfs
cp -Rp ~/.avfs/tmp/omeka-1.5.1.zip\#/omeka-1.5.1 omeka
Since we're assuming that there is a single toplevel directory in the archive, you can shorten this to
cp -Rp ~/.avfs/tmp/omeka-1.5.1.zip\#/* omeka
This script is not robust, but works in the simple cases:
...
dest=omeka
unzip omeka-1.5.1.zip -d $dest/
if [ `ls $dest | wc -l` == 1 ]; then
subdir=`ls $dest`
mv $dest/$subdir/* $dest/
rmdir $dest/$subdir
fi
It just checks to see if there is exactly one subdirectory, and if so, moves everything up out of it then deletes it.