How can I get 7z to extract the contents of a rar archive to the folder where it found the files?

I tried this and it just extracts to whichever folder I have my session in:

find ./ -name '*.rar' -exec 7z x -r {} \;

I want it to recurse through a set of folders and extract archives to the folder(s) where it found the archive.

2 Answers 2


Use -execdir instead of -exec to have 'find' change the "current" directory to where it found the files, before running 7z.


Use the e (Extract) command:

Extracts files from an archive to the current directory or to the output directory. The output directory can be specified by -o (Set Output Directory) switch.

This command copies all extracted files to one directory. If you want extract files with full paths, you must use x (Extract with full paths) command.

Example : To extract all files from archive archive.zip to the current directory

7z e archive.zip

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.