The Archives

  • 25.Nov.09
    Comparing directories in local or remote hosts shell | rafacas | (0)
    I frequently need to compare two directories (with similar structures) to find different or new files. When I have to compare them locally, I use the diff command. $ ls test* test: file1 file2 file3 file4 file5 test.new: file1 file2 file3 file4 file5 file6 $ diff -qr test test.new Files test/file2 and test.new/file2 differ Files test/file4 and test.new/file4 differ Only in test.new: file6 The -q option tells diff to tell only whether the files differ and the -r option is for recursively comparing inside subdirectories. A more complicated problem arises when the comparation has to be done remotely, that is one of the directories is in another host (Samba, NFS, etc ...
  • 22.Jun.09
    Cleaning port’s garbage shell | fernape | (0)
    portsclean cleans garbage from the directory tree of the ports collection. It is a utility of the base system that should be run from time to time to keep one's ports infrastructure as sane as possible. portsclean wipes old package files, unneeded libraries and such. There are several interesting option flags described in the man page. This is how I run portsclean from time to time: % portsclean -DD The command above cleans all the distfiles that are not referenced by any installed package in the system. I usually run this after rebuilding the complete userland from a new ports fetch. Enjoy!
  • 22.Feb.09
    Perl directory traversal scripts | pfortuny | (0)
    The following chunk of code sub traverse { my ($dir, $callback) = @_; my $present; opendir $present, $dir or return(); for (grep { ! /^(\.|\.\.)$/ } readdir $present) { my $path = "$dir/$_"; &$callback($path); traverse($path, $callback) if -d $path; } closedir $present; return(); } is an easy implementation (without error-checking) of a generic directory-traversing function in Perl. It should be called traverse(dir, ...