有趣的事实:如果您使用存档管理器并提取 .tar.gz 以便您取消选中“保持目录结构”,您将获得一个tarbomb。
tar -ztf
列出 tar 文件中的所有文件和目录。有没有办法在没有目录结构的情况下列出 tar 文件中的所有文件?
我已经看到 Bash 脚本指南建议使用数组来处理包含空格的文件名。然而,DashAsBinSh表明数组不可移植,所以我正在寻找一种符合 POSIX 的方式来处理可能包含空格的文件名列表。
我正在寻找修改下面的示例脚本,以便它 echo
foo/target/a.jar
foo/target/b.jar
bar/target/lol whitespace.jar
Run Code Online (Sandbox Code Playgroud)
这是脚本
#!/usr/bin/env sh
INPUT="foo/target/a.jar
foo/target/b.jar
bar/target/b.jar
bar/target/lol whitespace.jar"
# this would be produced by a 'ls' command
# We can execute the ls within the script, if it helps
dostuffwith() { echo $1; };
F_LOCATIONS=$INPUT
ALL_FILES=$(for f in $F_LOCATIONS; do echo `basename $f`; done)
ALL_FILES=$(echo "$ALL_FILES" | sort | uniq)
for f in $ALL_FILES
do
fpath=$(echo "$F_LOCATIONS" | grep -m1 $f)
dostuffwith $fpath
done
Run Code Online (Sandbox Code Playgroud)