简体   繁体   中英

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.

#!/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 . -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. So now the files has chown root:root as have all the files I wand to search through.

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

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 . I always get different variations of Permission denied errors.

Check if the filesystem was mounted with noexec flag.

But you can still run your script via bash :

bash /path/to/mysort.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM