我正在尝试创建一个脚本,该脚本可以将多个目录中具有特定扩展名的文件压缩为单个 tar 球。目前我在脚本文件中的内容是:
find "$rootDir" -name '*doc' -exec tar rvf docs.tar {} \;
Run Code Online (Sandbox Code Playgroud)
$rootDir搜索的基本路径在哪里。
这很好,除了 tar 文件中的路径是绝对的。我更喜欢路径相对于$rootDir. 我该怎么做呢?
当前的实施例tar -tf docs.tar,其中$rootDir是/home/username/test输出:
home/username/test/subdir/test.doc
home/username/test/second.doc
Run Code Online (Sandbox Code Playgroud)
我希望输出是什么:
./subdir/test.doc
./second.doc
Run Code Online (Sandbox Code Playgroud)