[英]Linux find -exec permission denied
I wrote a shell script iterating through files and ordering their contents and saving the new order back to the file. 我编写了一个Shell脚本来遍历文件并对其内容进行排序,然后将新命令保存回文件中。
#!/bin/sh
for i in "$@"; do
sort $i -k2 -o $i
done
The files to be sorted are chosen with the find
command like so: 使用find
命令选择要排序的文件,如下所示:
find . -regex '<myregex>' -exec ./mysort.sh {} +
I wrote the script and tried it out one machine as a specific user and then copied it over to another machine using root privileges. 我编写了脚本,并以特定用户的身份在一台计算机上进行了尝试,然后使用root特权将其复制到另一台计算机上。 So now the files has chown root:root
as have all the files I wand to search through. 因此,现在文件具有chown root:root
以及我想要搜索的所有文件。
So now the files to be sorted are located in the same folder as the mysort.sh and when I try to execute the find with -exec i get 因此,现在要排序的文件位于与mysort.sh相同的文件夹中,当我尝试使用-exec执行查找时,我得到了
find: './mysort.sh': Permission denied
I tried moving the script to a subfolder and executing the command with -exec ./folder/mysort.sh
or moving it to a higher level folder and executing it with -exec ../mysort.sh
. 我尝试将脚本移至子文件夹,然后使用-exec ./folder/mysort.sh
执行命令,或者将其移至更高级别的文件夹,然后使用-exec ../mysort.sh
执行它。 I always get different variations of Permission denied errors. 我总是会得到不同的“权限被拒绝”错误。
Check if the filesystem was mounted with noexec
flag. 检查文件系统是否已使用noexec
标志挂载。
But you can still run your script via bash
: 但是您仍然可以通过bash
运行脚本:
bash /path/to/mysort.sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.