Finding files inside an archive with Terminal
Looking for files inside an archive, without having to extract them first using Apple's Terminal.
find command
How to find files inside an archive, without having to extract them first using Apple’s Terminal, or any Unix / Linux bash shell.
❯ find /dir/ -iname archive.tar -print0 | \
xargs -0 tar t -f | grep "filename you are searching for"
❯ find /dir/ -iname archive.zip -print0 | \
xargs -0 unzip -l | grep "filename you are searching for"
❯ find /dir/ -iname archive.rar -print0 | \
xargs -0 unrar l | grep "filename you are searching for"
Command breakdown
- find /dir/
- use the powerful find command, inside the folder where the archive is
- -iname archive.tar
- look for the archive (case insensitive search)
- -print0
- when files are found, spit them out in a list with a NULL at the end instead of a new line - this helps with the next step
- |
- pass the list generated by find to the next command...
- xargs -0
- ...which is xargs, used to take a list of results and pass them on. The -0 is telling xargs to use NULL as the separator
- tar t -f
- use tar to list (t) the content of the archive, files only (-f)
- unzip -l
- use unzip to list the content of the archive
- unrar l
- use unrar to list the content of the archive
- |
- pass the list generated by find to the next command...
- grep "filename you are searching for"
- only show the items in the list that match the fillename, using grep