Celeb Glow
general | March 09, 2026

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
etc

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

0

5 Answers

Unfortunately, you can't. Your only real option is to just move them after they are extracted.

2

You might want to try the tar command, which has a --strip-components feature and can operate on zip files.

3

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; done

Simple 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy