在文件夹下找到(.BMP)文件的完整路径名,附加到文件

时间:2016-06-07 14:10:22

标签: shell find append

我在一个文件夹中有11个 .bmp 图片。我想创建一个文本文件,其中每一行都是图像名称的完整路径。 我使用了以下代码:

#!/bin/bash

i=0
find -type f -iname "*.bmp" | while read x; do
    echo $(cd $(dirname "$1") && pwd -P)/$(basename "$1") >>test2.txt 
    app=$( printf "%05d" ${i}).bmp
    #echo $app
    echo $(sed '${s/$/'"${app}"'/;}'  test2.txt) 
    i=$((i+1))
done

......但它不起作用。  所有图像都在这条路径中:/ home / behzad / Desktop / test / 我想要一个文本文件,每行如下:/home/behzad/Desktop/test/00000.bmp /home/behzad/Desktop/test/00001.bmp ... /home/behzad/Desktop/test/00011.bmp

2 个答案:

答案 0 :(得分:2)

.bmp和子目录中的所有~/foo/bar个文件的完整路径名打印到新的输出文件test2.txt

s=~/foo/bar    # full path of dir to be searched.
find "$s" -iname "*.bmp" -type f -fprint test2.txt

test2.txt的不同目录中添加更多名称:

s=~/oof/rab    # full path of dir to be searched.
find "$s" -iname "*.bmp" -type f >> test2.txt

答案 1 :(得分:0)

我使用了以下代码并完成了:)

#!/bin/bash
i=0
find -type f -iname "*.bmp" | while read x; do
    echo $(cd $(dirname "$1") && pwd -P)/$(basename "$1") >>test1.txt 
    app=$( printf "%05d" ${i}).bmp
    echo $app >>test2.txt
    i=$((i+1))
done

paste -d "" test1.txt test2.txt > path.txt