2013-12-16 52 views
0

我已經使用find,foundlist.lst創建了一個文件列表。有沒有更好的方法來查找目錄樹中的文件列表

find命令僅僅是find . -type f -name "<search_pattern>" > foundlist.lst

我現在想用這個列表來查找這些文件的副本在其他目錄。

我的要求中的「扭曲」是我只想搜索文件名的「基礎」。我不想在搜索中包含擴展名。

實施例:

./sort.cc是列表中的一員。我想尋找模式的所有文件sort.*

這是我寫的。有用。在我看來,有一種更有效的方式來做到這一點。

./findfiles.sh foundfiles.lst /usr/bin/temp 

#!/bin/bash 
# findfiles.sh 
if [ $# -ne 2 ]; then 
    echo "Need two arguments" 
    echo "usage: findfiles <filelist> <dir_to_search>" 
else 
    filename=$1 
    echo "$filename" 
    while read -r line; do 
     name=$line 
     # change './file.ext' to 'file.*' 
     search_base=$(echo ${name} | sed "s%\.\/%%" | sed "s/\..*/\.\*/") 
     find $2 -type f -name $search_base 
    done < $filename 
fi 
+0

http://codereview.stackexchange.com是這個問題 –

+0

@AndyJones感謝您最好的地方。 – KeithSmith

回答

1

對於剝離的文件,我會使用以下(而不是AWK)

search_base=`basename ${name} | cut -d'.' -f1` 
相關問題