Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 bash 世界完全陌生,我目前正在编写一个脚本,该脚本将遍历一个大目录并将找到的任何 .tar 文件提取到当前位置。
我正在使用以下脚本:
for a in in /home/davidwright/attachments/*/*.tar do echo "extracting $x" tar -xvf $x done
目前该文件正在提取正常,但它正在提取到我的脚本的位置。我需要它在 .tar 的当前目录中提取。
解决方案可能很简单,但我一生都无法弄清楚。谢谢!
你可以试试:
-C, --directory DIR change to directory DIR
和$(dirname "$x")文件目录
$(dirname "$x")
for x in in /home/davidwright/attachments/*/*.tar do echo "extracting $x" tar -xvf "$x" -C "$(dirname "$x")" done