2014-02-25 284 views
0

我有一個包含24個子目錄的目錄,沒有按時間順序排列 我需要輸入一個子目錄,解壓縮一個文件,然後在解壓文件中調用「tophat」命令,然後移到下一個子目錄。循環應該通過這些命令遍歷所有的子目錄。 我真的不知道如何創建這個循環(我需要它在顯示器上運行,而不是按照數字順序運行)「for」在shell中循環遍歷目錄

(肯定你們中許多使用RNA-seq結果的人都熟悉這個問題) 如果有人能幫助我與它 我會很感激

+0

不高頂禮帽可以作爲'解壓文件-c |頂禮帽' – BMW

回答

0

使用find

find /path -type d -print | \ 
while read path ; do 
    ... 
done 

注:此循環中斷時的文件名包含換行字符。

-1

同樣使用循環

for directory in `find /path -type d -print` 
do 
    cd "$directory" 
    unzip zip_filename 
    sh zip_dir/script_file.sh & 
done 
+0

迭代的'這樣find'輸出不是安全的;當文件名包含當前的分詞字符時它會中斷。 – chepner

1
for d in "/path/to/"*/ 
do 
    cd "$d" || continue 
    unzip the_file.zip 
    tophat the_file 
done