2016-09-20 99 views

回答

0

试试这个:

#!/bin/bash 

if [[ ! $1 || $1 == -h || $1 == --help ]]; then 
    echo -e "Usage:\n\n\t$0 '[path/]<file name>'" 
    exit 1 
fi 

files=(
    $(file 2>/dev/null /proc/*/fd/* | 
     grep "(deleted)'$" | 
     sed -r '[email protected](:.*broken\s+symbolic\s+link\s+to\s+.|\(deleted\).$)@ @g' | 
     grep "$1" | 
     cut -d' ' -f1 
    ) 
) 

if [[ ${files[@]} ]]; then 
    for f in ${files[@]}; do 
     echo "fd $f match... Try to copy this fd to another place quickly!" 
    done 
else 
    echo >&2 "No matching fd found..." 
    exit 2 
fi 

没有测试在非GNU Linux的

+0

不要忘记给予好评/接受,如果答案满足您的需求。检查http://stackoverflow.com/help/why-vote和http://stackoverflow.com/help/accepted-answer –

+0

该文件是一个字符的Spl文件,没有权限如何解决此问题 –

+0

您应该拥有读取权限,请尝试复制:'cp/dev/fd42/tmp/backup'。这不是一个渴望被编辑打开的文件。这是一个特殊的文件 –