I want to create a tar ball and include only the files in the directory that start with a specific filename. For instance I have apples-x.x.x and oranges-x.x.x, and I only want to tar the files beginning with "apple". How can I do this?
Thanks!
I want to create a tar ball and include only the files in the directory that start with a specific filename. For instance I have apples-x.x.x and oranges-x.x.x, and I only want to tar the files beginning with "apple". How can I do this?
Thanks!
Maybe something like that:
find / -type f -name "apple*" -exec tar -rf archive.tar '{}' \;
Its better than tar cf /path/tarfile appl*
beacause dont archive directory with pattern apple*
Ummm, I may be overlooking something, but how about
tar cf /path/tarfile appl*
Unless you have directories which are also called ./appl*
, in which case they'll get trawled up, with their contents, that should do it. If the latter pertains, you can stop that with --no-recursion
.
What about
find / -type f -name "apple*" -exec tar -cf archive.tar '{}' \+
? This way it would pass all file names to tar in a single shot (see -exec command {} + on the find man page).
For multiple files with different patterns, one could use
find ./ -type f \( -name "apple*" -o -name "orange*" -o -name "berries*" -o -name "lemons*" \) -exec tar -cf archive.tar '{}' \+
This is based on the answers from B14D3 and al0, and the link here : https://www.tecmint.com/linux-find-command-to-search-multiple-filenames-extensions/