Operating System - HP-UX
1832978 Members
3131 Online
110048 Solutions
New Discussion

how can I 'tar' my source files

 
SOLVED
Go to solution
Peter Hug
Advisor

how can I 'tar' my source files

I'm trying to use tar to create a tar file that includes all the *.h and *.cpp files in all subdirectories and includes their relative path.

I thought I could do something like:

tar cvf backup.tar -c . *.h *.cpp

but this seems to ignore ' *.h *.cpp' and stores everything?

I'm lost.
3 REPLIES 3
Sundar_7
Honored Contributor
Solution

Re: how can I 'tar' my source files

Try this

tar -cvf backup.tar $(find . -name "*.h" -o -name "*.cpp" -print)

Learn What to do ,How to do and more importantly When to do ?
Sยภเl Kย๓คг
Respected Contributor

Re: how can I 'tar' my source files

Sunder is absolutely correct
tar -cvf backup.tar $(find . -name "*.h" -o -name "*.cpp" -print) will do
regards
SK
Your imagination is the preview of your life's coming attractions
Muthukumar_5
Honored Contributor

Re: how can I 'tar' my source files

hai guru sundar,

tar -cvf backup.tar $(find . -name "*.h" -o -name "*.cpp" -print) will not work here.

I will only get *.h header files only not *.cpp files.

while using -o option we have to use () on this as,

tar -cvf backup.tar $(find . \( -name "*.h" -o -name "*.cpp" \) -print)

It will work now.

Else simply as,

tar -cvf backup.tar `find . -name "*.h" -o -name "*.cpp"`

It will work there.

Easy to suggest when don't know about the problem!