vincepare / dirscan
文件系统扫描器
1.3.0
2017-12-10 15:18 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-13 15:32:18 UTC
README
DirScan是一款文件目录命令行工具,可以将目录及其子目录下的所有文件列表输出到文本文件中,包括文件属性如时间戳和权限。
它可以用来比较不同时间整个分区内的所有文件,查看它们之间的变化。
示例
dirscan --deep --same-device / > "drive-content.txt"
DirScan自带文本报告器,但您可以通过创建自己的报告类来自定义输出,允许将数据保存到CSV、XML或SQLite数据库等。
下载
下载dirscan.phar,将其设置为可执行(chmod +x dirscan.phar),如果需要的话可以重命名。在Linux上,将其存储到/usr/local/bin
以便在所有地方使用。
wget -O dirscan https://github.com/vincepare/DirScan/releases/download/1.3.0/dirscan.phar
chmod +x dirscan
sudo mv dirscan /usr/local/bin/dirscan
更新
wget -O "$(which dirscan)" https://github.com/vincepare/DirScan/releases/download/1.3.0/dirscan.phar
需求
已在PHP 5.3、5.4、5.5和5.6上测试。还有一个旧版本适用于PHP 5.2,但有一些限制。
用法
Usage :
dirscan [OPTIONS] TARGET...
Options :
--help, -h This help message
--version, -v Print software version
--deep, -d Explore symbolic links (default : skip)
--flat, -f Do not explore subdirectories
--same-device Explore only directories on the same device as the start directory
Useful on Linux, to ignore special mount points like /sys or /proc
--access, -a Report access time
--htime, -t Report user friendly date nearby unix timestamps
--perms, -p Report file permissions
--full Report all properties
--format=STRING Custom reporting format, call with empty string to print format help
格式
格式令牌以自定义输出(--format
)
%u Unique path
%t Type
%s Size
%c ctime
%C Change time
%m mtime
%M Modify time
%a atime
%A Access time
%p Permissions
%o UID
%O Owner
%g GID
%G Group
%i Inode
%e Extended
程序化使用
虽然dirscan以命令行工具的形式发布,但您也可以使用其内部的DirScan
类作为文件系统迭代器。Dirscan可作为composer包使用。
composer require vincepare/dirscan
如何使用
require 'vendor/autoload.php'; use Vincepare\DirScan\DirScan; use Vincepare\DirScan\Reporter; class MyReporter extends Reporter { public $files = []; public function push($node, DirScan $scanner) { $this->files[] = $node['path']; } } $settings = ['flat' => true]; $reporter = new MyReporter(); $scanner = new DirScan($settings, $reporter); $scanner->scan('/tmp'); print_r($reporter->files);
关于Windows
DirScan设计用于Unix环境(Linux或Mac OS),但您也可以在Windows上使用它。在这种情况下,请注意,旧版PHP发布版本可能无法正确处理NTFS连接点和非符号链接(请参阅readlink & is_link)。但您最好使用其他工具,如WhereIsIt。