Create a tar archive called jpgs.tar
of only JPEG image files in directory/
(at all directory levels).
You can use this short tar command.
tar -cvf jpgs.tar directory/**/*.jp*g
Or this more verbose tar command.
tar --create --verbose --file jpgs.tar directory/**/*.jp*g
The **/*.jp*g
format does the recursion. Ie. finding JPEG's and JPG's at any level in the directory structure.
Note: There are alternative ways to build a list of files by filetype using the find
command and then piping that into tar
. However, if you want to achieve this with tar only, the above command should work on your tar implementation.
-c
or --create
tells tar to create a new archivev
or --verbose
tells tar to produce verbose outputf
or --file
tells tar that the next parameter will be the tar file to create, extract, append to, list, etc.