-2

我正在寻找可以执行以下操作的脚本:

我有一组普通文件,例如“myFile.log”,我想保留它们的当前状态。

我想将所有类型的文件myFile.log.year-month-day-hour放入 gzip 压缩的 tar 存档中,每天都有单独的子文件夹。

谁能指出我如何完成这项工作的正确方向?

4

1 回答 1

1

如果你想对 Ruby 中的文件做任何有趣的事情,你需要

require 'fileutils'

在 IRB 中查看您可以使用的方法

1.9.3-p327 :001 > require 'fileutils'
 => true
1.9.3-p327 :002 > File.methods.sort - Object.methods
 => [:absolute_path, :atime, :basename, :binread, :binwrite, :blockdev?, :chardev?, :chmod, :chown, :copy_stream, :ctime, :delete, :directory?, :dirname, :executable?, :executable_real?, :exist?, :exists?, :expand_path, :extname, :file?, :fnmatch, :fnmatch?, :for_fd, :foreach, :ftype, :grpowned?, :identical?, :join, :lchmod, :lchown, :link, :lstat, :mtime, :open, :owned?, :path, :pipe, :pipe?, :popen, :read, :readable?, :readable_real?, :readlines, :readlink, :realdirpath, :realpath, :rename, :select, :setgid?, :setuid?, :size, :size?, :socket?, :split, :stat, :sticky?, :symlink, :symlink?, :sysopen, :truncate, :try_convert, :umask, :unlink, :utime, :world_readable?, :world_writable?, :writable?, :writable_real?, :write, :zero?]
1.9.3-p327 :007 > FileUtils.methods.sort - Object.methods
 => [:cd, :chdir, :chmod, :chmod_R, :chown, :chown_R, :cmp, :collect_method, :commands, :compare_file, :compare_stream, :copy, :copy_entry, :copy_file, :copy_stream, :cp, :cp_r, :getwd, :have_option?, :identical?, :install, :link, :ln, :ln_s, :ln_sf, :makedirs, :mkdir, :mkdir_p, :mkpath, :move, :mv, :options, :options_of, :private_module_function, :pwd, :remove, :remove_dir, :remove_entry, :remove_entry_secure, :remove_file, :rm, :rm_f, :rm_r, :rm_rf, :rmdir, :rmtree, :safe_unlink, :symlink, :touch, :uptodate?]
1.9.3-p327 :013 > Dir.methods.sort - Object.methods
 => [:[], :chdir, :chroot, :delete, :entries, :exist?, :exists?, :foreach, :getwd, :glob, :home, :mkdir, :open, :pwd, :rmdir, :unlink]

从 eg 开始Dir.entries('/path'),并使用 Ruby 的数组方法来处理列表,使用正则表达式来提取部分名称等

于 2013-04-17T09:48:21.223 回答