Say I have the following directory tree
.
├── a1
│ └── sub1
│ └── a1.zip
└── a2
└── sub2
└── a2.zip
The current directory contains a1
and a2
directories. I want to recursively search, locate and extract all zip files, and move everything up to a1
and a2
respectively. The goal state is:
.
├── a1
│ ├── file1
│ └── file2
└── a2
├── file1
└── file2
Where the files came from the zip. How do I accomplish that? What tools should I use in Terminal for that?
EDIT
To be more specific, I mention the recursion since we don't know how many subdirectories there are. It could be:
.
├── a1
│ └── sub1
│ └── sub...
│ └── a1.zip
│ └── text1.txt
└── a2
└── sub2
└── sub...
└── a2.zip
└── text2.txt
Goal:
.
├── a1
│ ├── file1_unzipped
│ └── text1.txt
└── a2
├── file1_unzipped
└── text2.txt
.zip
archivesfind . -type f -name "*.zip" -exec unzip {} +
find .
– search current directory for-type f
– files-name "*.zip"
– whose name match *.zip
(so ends in .zip
),-exec unzip {} +
– make one long list of all matches and and run unzip
on itfor i in */; do find "$i" -type f -exec mv {} "$i" \; && rm -r "$i"*/; done
for i in */; do …; done
– loop over all directories on the current levelfind "$i" -type f
– search all files in the currently processed directory and below-exec mv {} "$i" \;
– move them to the currently processed directory&&
do the following only if the previous command finished successfullyrm -r "$i"*/
– remove every subdirectory in the currently processed directoryCollected from the Internet
Please contact [email protected] to delete if infringement.
Comments