Results 1 to 4 of 4

Thread: how to tar subdirectories by file type?

  1. #1

    how to tar subdirectories by file type?

    Does anyone know how I can tar a directory and all its subdirectories, but only of a given file type?

    For example, I'd like to take only the .php files from:

    dir/subdir/file.php
    dir/subdir/file2.php
    dir/subdir/file.txt
    dir/file.php
    dir/file.txt

    Thus only archiving the 3 .php files.

    I tried tar -cvf dir/*.php but it didn't go into subdir.

    I know in this case I could do it manually pretty easily but I'm trying to do it with a directory that has about 20 subdirectories (some of which have subdirectories) and a large number of files in each.

    Any help?

    Thanks,
    Seth

  2. #2
    Advisor Outlaw's Avatar
    Join Date
    May 2001
    Location
    Clifton Park, NY
    Posts
    630

    Re:how to tar subdirectories by file type?

    How about:
    Code:
    [radar@Dell-i8500 tmp]$ find junk
    junk
    junk/stuff
    junk/stuff/2.php
    junk/stuff/who.txt
    junk/stuff/crap
    junk/stuff/crap/where.txt
    junk/stuff/crap/3.php
    junk/1.php
    junk/what.txt
    Code:
    [radar@Dell-i8500 tmp]$ tar cvzf - `find junk -type f -name "*.php"` >files_php.tar.gz
    junk/stuff/2.php
    junk/stuff/crap/3.php
    junk/1.php
    [radar@Dell-i8500 tmp]$ tar tzf files_php.tar.gz 
    junk/stuff/2.php
    junk/stuff/crap/3.php
    junk/1.php

  3. #3

    Re:how to tar subdirectories by file type?

    [quote author=Radar link=board=1;threadid=10827;start=0#msg97046 date=1133811504]
    How about:
    Code:
    [radar@Dell-i8500 tmp]$ find junk
    junk
    junk/stuff
    junk/stuff/2.php
    junk/stuff/who.txt
    junk/stuff/crap
    junk/stuff/crap/where.txt
    junk/stuff/crap/3.php
    junk/1.php
    junk/what.txt
    Code:
    [radar@Dell-i8500 tmp]$ tar cvzf - `find junk -type f -name "*.php"` >files_php.tar.gz
    junk/stuff/2.php
    junk/stuff/crap/3.php
    junk/1.php
    [radar@Dell-i8500 tmp]$ tar tzf files_php.tar.gz 
    junk/stuff/2.php
    junk/stuff/crap/3.php
    junk/1.php
    [/quote]

    That does it.

    Awesome, thank you.

  4. #4
    Member AljoshaNL's Avatar
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    230

    Re:how to tar subdirectories by file type?

    [quote author=SethLeonard link=board=1;threadid=10827;start=0#msg97044 date=1133809828]
    Does anyone know how I can tar a directory and all its subdirectories, but only of a given file type?

    For example, I'd like to take only the .php files from:

    dir/subdir/file.php
    dir/subdir/file2.php
    dir/subdir/file.txt
    dir/file.php
    dir/file.txt

    Thus only archiving the 3 .php files.

    I tried tar -cvf dir/*.php but it didn't go into subdir.

    I know in this case I could do it manually pretty easily but I'm trying to do it with a directory that has about 20 subdirectories (some of which have subdirectories) and a large number of files in each.

    Any help?

    Thanks,
    Seth
    [/quote]
    It is easier:
    tar -cvf -recursion dir/*.php

Similar Threads

  1. How to use the Sysprep tool
    By CoolJsa14 in forum Windows - General Topics
    Replies: 0
    Last Post: 01-05-2005, 09:34 PM
  2. GL not working ati 7000
    By Mip in forum Linux - Software, Applications & Programming
    Replies: 19
    Last Post: 10-28-2004, 09:29 PM
  3. Calling all mail server admins
    By demian in forum Linux - Hardware, Networking & Security
    Replies: 4
    Last Post: 04-21-2004, 08:21 PM
  4. problems compiling fealnx.c
    By jjanela in forum Linux - Software, Applications & Programming
    Replies: 15
    Last Post: 01-04-2003, 10:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •