The following commands will search in the .tar archives found in the specified folder and print on screen all files that their paths or filenames match our search token. We provide multiple solutions, each one for a different type of .tar archive depending on the compression used.
For .tar archives
find /media/repository/packages/ -type f -iname "*.tar" -exec tar -t -f '{}' \; | grep "configurations/arm-cortexa9";
For .tar.bz2 archives
find /media/repository/packages/ -type f -iname "*.tar.bz2" -exec tar -t -j -f '{}' \; | grep "configurations/arm-cortexa9";
For .tar.xz archives
find /media/repository/packages/ -type f -iname "*.tar.xz" -exec tar -t -J -f '{}' \; | grep "configurations/arm-cortexa9";
For .tar.gz and .tgz archives
Please note that this commands uses the -o (which is the logical or) parameter on find to search for multiple filename extensions.
find /media/repository/packages/ -type f \( -iname "*.tar.gz" -o -iname "*.tgz" \) -exec tar -t -z -f '{}' \; | grep "configurations/arm-cortexa9";
find Parameters Legend
-type ffilters out any result which is not a regular file-exec command '{}' \;runs the specified command on the results of find. The string'{}'is replaced by the current file name being processed.-ois the logicalOroperator. The second expression is not evaluated if the first expression is true.
tar Parameters Legend
-zor--gzipinstructs tar to filter the archive throughgzip-jor--bzip2filters the archive throughbzip2-Jor--xzfilters the archive throughxz-tor--listlists the contents of an archive-for--file=INPUTuses the archive file or device named INPUT
This post is also available in: Greek


