2016-09-20 96 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'。這不是一個渴望被編輯打開的文件。這是一個特殊的文件 –