You have a compressed tar archive file named:
mingw-w64-i686-headers-git-5.0.0.4774.3b51067b-1-any.pkg.tar.xz
Inside it, there's a file:
mingw32/i686-w64-mingw32/include/psapi.h
You want to extract just that file but place it in a target directory (on your system) under:
mingw32/include/psapi.h
(i.e., without the intermediate i686-w64-mingw32 folder).
How to do that?
You want to extract only that one file, and place it into mingw32/include/ instead of the full directory tree.
By default, tar preserves the internal paths. To modify paths when extracting, the easiest way is extracting and restructuring, or using some GNU tar options that allow to strip components.
Step-by-step
- Create the target directory (if not exists):
mkdir -p mingw32/include
- Inspect the archive's structure (optional):
tar -tf mingw-w64-i686-headers-git-5.0.0.4774.3b51067b-1-any.pkg.tar.xz | grep psapi.h
You expect the output to be:
mingw32/i686-w64-mingw32/include/psapi.h
- Extract the file, stripping components
GNU tar has the option --strip-components=N that removes the leading N directory levels.
-
The path is mingw32/i686-w64-mingw32/include/psapi.h
-
To get just mingw32/include/psapi.h in the extracted files, you have to strip i686-w64-mingw32/ (which is the 2nd path component maybe?)
Let's map the path components:
- 1: mingw32
- 2: i686-w64-mingw32
- 3: include
- 4: psapi.h
You want "mingw32/include/psapi.h", which is components 1 + 3 + 4.
If you do
--strip-components=1
then the first component mingw32 is removed, resulting path:
i686-w64-mingw32/include/psapi.h
Not what you want.
If you do --strip-components=2, you remove mingw32/i686-w64-mingw32 resulting:
include/psapi.h only — missing the mingw32 folder.
So what do you do now?
One way:
-
Extract the file normally somewhere (say, current directory),
-
Then move it to mingw32/include
Or, extract with --strip-components=2, saving into temp/include/psapi.h, then move temp/include to mingw32/include/.
Example command:
mkdir -p temp
tar -xJf mingw-w64-i686-headers-git-5.0.0.4774.3b51067b-1-any.pkg.tar.xz mingw32/i686-w64-mingw32/include/psapi.h --strip-components=2 -C temp
This extracts include/psapi.h into temp/include/psapi.h.
Then:
mkdir -p mingw32/include
mv temp/include/psapi.h mingw32/include/
rmdir temp/include
rmdir temp
Now you have the file at mingw32/include/psapi.h
Alternative: Extract without --strip-components in temp and then move
mkdir -p temp
tar -xJf mingw-w64-i686-headers-git-5.0.0.4774.3b51067b-1-any.pkg.tar.xz mingw32/i686-w64-mingw32/include/psapi.h -C temp
You will get:
temp/mingw32/i686-w64-mingw32/include/psapi.h
Then move the file:
mkdir -p mingw32/include
mv temp/mingw32/i686-w64-mingw32/include/psapi.h mingw32/include/psapi.h
Cleanup:
rm -r temp
Summary
The main limitation here is that tar cannot delete intermediate directories selectively. You can only strip leading components.
If you want to preserve mingw32/include/ but not i686-w64-mingw32/, it is a little tricky.
A straightforward script to do this:
# Create target directory
mkdir -p mingw32/include
# Extract the file with full path to temp directory
mkdir -p temp
tar -xJf mingw-w64-i686-headers-git-5.0.0.4774.3b51067b-1-any.pkg.tar.xz mingw32/i686-w64-mingw32/include/psapi.h -C temp
# Move the file to desired location
mv temp/mingw32/i686-w64-mingw32/include/psapi.h mingw32/include/
# Remove temp directory
rm -rf temp
Let me know if you want the command in one line or a script for convenience.