找到/ template文件夹中的所有* .tpl文件,并递归地chmod它们666

时间:2016-01-08 19:06:06

标签: linux permissions find chmod

我需要在/ template文件夹中找到所有* .tpl文件,并递归地chmod它们。顺便说一下,chmoding文件递归意味着什么?我想它会找到所有* .tpl文件并将它们chmod到666.这将是递归的吗?

我有这个,它不起作用:

find /template -type f \( -iname "*.tpl" \) | xargs chmod 666

有没有更好的办法做这样的事情?

1 个答案:

答案 0 :(得分:0)

进一步回答你自己的问题:),你也可以在脚本中执行以下操作,尽管你的单线程工作。我添加了一些代码,因此您可以重新运行此脚本以查看不同的目录。

#!/bin/bash
if [[ $1 = "" ]] ; then
  echo "Please provide a directory to the script... For example: ./thisScript /directoryTosearch"
  exit 2
fi

for i in $(find $1 -type f -iname "*.tpl") ; do
  echo "Changing permissions on ${i}"
  chmod 666 ${i}
done

我通过回显,这样你就可以在屏幕上显示一个很好的输出,说明更改了哪些文件。

相关问题