gplantz has asked for the wisdom of the Perl Monks concerning the following question:

I know this is probably an FAQ, but I need to find a way to locate and move any hidden files with Perl on a Unix box, under a specific directory ( or it's subdirectories ). From what I've found, the file patern would something like '.*' Thanks in advance for any help. Glen Plantz
  • Comment on Finding and Moving hidden files in Unix

Replies are listed 'Best First'.
Re: Finding and Moving hidden files in Unix
by moritz (Cardinal) on Nov 24, 2008 at 23:02 UTC
    For recursively finding files, File::Find is usually recommended. If you don't like (or understand) its interface, you can use File::Find::Rule instead.
      The usage for the latter would be
      use File::Find::Rule qw( ); my @files = File::Find::Rule ->file() ->name( '.*' ) ->in( $base_dir );

      @files contains qualified paths. You can then use File::Copy's move to move the files.

Re: Finding and Moving hidden files in Unix
by oeuftete (Monk) on Nov 24, 2008 at 23:28 UTC
    The finding part:
    use File::Find; find (\&wanted, '/your/directory'); sub wanted { print $File::Find::name . "\n" if ( /^\./ && -f $_ ); }
Re: Finding and Moving hidden files in Unix
by JavaFan (Canon) on Nov 25, 2008 at 01:38 UTC
    Assuming you want to move all the files to a specific directory, I'd use something like:
    $ find source_dir -type f -name '.*' -print0 | xargs -0 -i mv '{}' tar +get_dir
    Tailor to taste.