Skip to main content
Correct typo, add more explanation
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 78

This looks like a job for find. Change to the directory dir, and issue the following command:

find . -type f -name "archive.zip" -execdir unzip {} \; 
  • This will search all directories starting with the current (., which is equal to dir in your case) for files (-type f) with the name archive.zip.
  • If found, it will execute the command unzip {} in the directory where the file was found (-execdir), with {} being the reference to the name of the found file (which find will replace with the actual filename - in this case, simply archive.zip).

It will have the same effect as saying cd 001/; unzip archive.zip; cd ..; cd 002/; unzip archive.zip ... (I think you get the point).

NoteNote that the ; terminating the command-to-be-executed must really be escaped with a \, otherwise the shell will interpret it before it reaches find. 

Also, if the dir/ directoriesdirectory itself can contain an archive.zip that you don't want extracted, you have to add the -mindepth 1 argument after the starting point . to ensure that find only considers files starting at the first subdirectory-level below dir/.

This looks like a job for find. Change to the directory dir, and issue the following command:

find . -type f -name "archive.zip" -execdir unzip {} \; 
  • This will search all directories starting with the current (., which is equal to dir in your case) for files (-type f) with the name archive.zip.
  • If found, it will execute the command unzip {} in the directory where the file was found (-execdir), with {} being the reference to the name of the found file (which find will replace with the actual filename - in this case, simply archive.zip).

It will have the same effect as saying cd 001/; unzip archive.zip; cd ..; cd 002/; unzip archive.zip ... (I think you get the point).

Note that the ; terminating the command-to-be-executed must really be escaped with a \, otherwise the shell will interpret it before it reaches find. Also, if the dir directories itself can contain an archive.zip that you don't want extracted, you have to add the -mindepth 1 argument after the starting point ..

This looks like a job for find. Change to the directory dir, and issue the following command:

find . -type f -name "archive.zip" -execdir unzip {} \; 
  • This will search all directories starting with the current (., which is equal to dir in your case) for files (-type f) with the name archive.zip.
  • If found, it will execute the command unzip {} in the directory where the file was found (-execdir), with {} being the reference to the name of the found file (which find will replace with the actual filename - in this case, simply archive.zip).

It will have the same effect as saying cd 001/; unzip archive.zip; cd ..; cd 002/; unzip archive.zip ... (I think you get the point).

Note that the ; terminating the command-to-be-executed must really be escaped with a \, otherwise the shell will interpret it before it reaches find. 

Also, if the dir/ directory itself can contain an archive.zip that you don't want extracted, you have to add the -mindepth 1 argument after the starting point . to ensure that find only considers files starting at the first subdirectory-level below dir/.

Add more explanation
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 78

This looks like a job for find. Change to the directory dir, and issue the following command:

find . -type f -name "archive.zip" -execdir unzip {} \; 
  • This will search all directories starting with the current (., which is equal to dir in your case) for files (-type f) with the name archive.zip.
  • If found, it will execute the command unzip {} in the directory where the file was found (-execdir), with {} being the reference to the name of the found file (which find will replace with the actual filename - in this case, simply archive.zip).

It will have the same effect as saying cd 001/; unzip archive.zip; cd ..; cd 002/; unzip archive.zip ... (I think you get the point).

Note that the ; terminating the command-to-be-executed must really be escaped with a \, otherwise the shell will interpret it before it reaches find. Also, if the dir directories itself can contain an archive.zip that you don't want extracted, you have to add the -mindepth 1 argument after the starting point ..

This looks like a job for find. Change to the directory dir, and issue the following command:

find . -type f -name "archive.zip" -execdir unzip {} \; 
  • This will search all directories starting with the current (., which is equal to dir in your case) for files (-type f) with the name archive.zip.
  • If found, it will execute the command unzip {} in the directory where the file was found (-execdir), with {} being the reference to the name of the found file (which find will replace with the actual filename - in this case, simply archive.zip).

Note that the ; terminating the command-to-be-executed must really be escaped with a \, otherwise the shell will interpret it before it reaches find. Also, if the dir directories itself can contain an archive.zip that you don't want extracted, you have to add the -mindepth 1 argument after the starting point ..

This looks like a job for find. Change to the directory dir, and issue the following command:

find . -type f -name "archive.zip" -execdir unzip {} \; 
  • This will search all directories starting with the current (., which is equal to dir in your case) for files (-type f) with the name archive.zip.
  • If found, it will execute the command unzip {} in the directory where the file was found (-execdir), with {} being the reference to the name of the found file (which find will replace with the actual filename - in this case, simply archive.zip).

It will have the same effect as saying cd 001/; unzip archive.zip; cd ..; cd 002/; unzip archive.zip ... (I think you get the point).

Note that the ; terminating the command-to-be-executed must really be escaped with a \, otherwise the shell will interpret it before it reaches find. Also, if the dir directories itself can contain an archive.zip that you don't want extracted, you have to add the -mindepth 1 argument after the starting point ..

Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 78

This looks like a job for find. Change to the directory dir, and issue the following command:

find . -type f -name "archive.zip" -execdir unzip {} \; 
  • This will search all directories starting with the current (., which is equal to dir in your case) for files (-type f) with the name archive.zip.
  • If found, it will execute the command unzip {} in the directory where the file was found (-execdir), with {} being the reference to the name of the found file (which find will replace with the actual filename - in this case, simply archive.zip).

Note that the ; terminating the command-to-be-executed must really be escaped with a \, otherwise the shell will interpret it before it reaches find. Also, if the dir directories itself can contain an archive.zip that you don't want extracted, you have to add the -mindepth 1 argument after the starting point ..