Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 监视目录并在创建时更改文件的所有权_Bash_Sed_While Loop_Chown_Inotifywait - Fatal编程技术网

Bash 监视目录并在创建时更改文件的所有权

Bash 监视目录并在创建时更改文件的所有权,bash,sed,while-loop,chown,inotifywait,Bash,Sed,While Loop,Chown,Inotifywait,我试过这个方法,但不起作用 inotifywait -mr -e create /opt/freeswitch/storage/ 2>&-| sed 's/ CREATE //g' | while read file; do chown apache.apache $file done 从命令行 inotifywait -mr -e create /opt/freeswitch/storage/ 2>&-| sed 's/ CREATE //

我试过这个方法,但不起作用

inotifywait -mr -e create /opt/freeswitch/storage/ 2>&-| sed 's/ CREATE //g' |
    while read file; do
    chown apache.apache $file
    done
从命令行

inotifywait -mr -e create /opt/freeswitch/storage/ 2>&-| sed 's/ CREATE //g'
提供我需要的文件完整路径的确切输出,但当我尝试将sed输出到文件或将其输出到其他文件时,它就停止工作


有人能给我指出正确的方向吗?

默认情况下,
sed
在写入管道时缓冲其输出。使用
-u
选项解除缓冲

inotifywait -mr -e create /opt/freeswitch/storage/ 2>&-| sed -u 's/ CREATE //g' |
    while read file; do
    chown apache.apache $file
    done