unzip how to trim top directories
I have a zip archive. The unzip -l myarchive.zip command gives this listing:
top/subtop/files/1.txt
top/subtop/files2/2.txt
etcThe root folders are top/subtop for all files. How to extract those files without the two top/subtop folders?
E.g. when I am in /home/myuser/public_html directory, files/1.txt and files2/2.txt shoud be extracted directly to that directory.
I tried unzip myarchive.zip top/subtop/* but it created top/subtop directories anyway.
5 Answers
Unfortunately, you can't. Your only real option is to just move them after they are extracted.
2You might want to try the tar command, which has a --strip-components feature and can operate on zip files.
Using JMeter as an example:
# It's a good idea to set JMETER_HOME.
export JMETER_HOME=/usr/local/jmeter
unzip -q /tmp/apache-jmeter-5.4.1.zip -d $JMETER_HOME
for a in `ls -d -1 $JMETER_HOME/*`; do mv $a/* $JMETER_HOME; rmdir $a; doneSimple and portable.
$ unzip myarchive.zip
$ mv top/subtop/* . 1 I used this command to copy all files to my root file directory after Extracting All zipped files, it worked great. Huge time saver:
for /r %f in (00P*) do @copy "%f" ()
1