Printing file paths using bash

时间:2016-07-11 19:38:01

标签: bash unix directory pwd

I am a student learning bash. I am currently trying to print a series of absolute file paths to run additional scripts with.

Currently echo $PWD, *In does not work. My file structure looks like.

/home/hayden/myProject/gene

within this directory there are several folders but I am specifically interested in three.

/largeIn/
/mediumIn/
/smallIn/

Within these folders there are differently named files that all end with .fa.

Is there a simple way to extract the files paths to a txt file?

to looks like this

/home/hayden/myProject/gene/largeIn/file.fa
/home/hayden/myProject/gene/mediumIn/file.fa
/home/hayden/myProject/gene/smallIn/file.fa

Thank you

EDIT: @Afle solution was successful.

1 个答案:

答案 0 :(得分:1)

Look at the standard Linux find utility. It will be your friend when you are working with any shell, not just bash. It's a general utility for finding files recursively within directories.

In your particular case, you'd do something like :

find /home/hayden/myProject/gene -name '*.fa'

This will find any files under /home/hayden/myProject/gene whose names end with ".fa" (even if they are multiple levels below "gene".

Now, if you know fr a fact that files are exactly where your examples are you could simply use bash's glob'ing and refer to them as :

/home/hayden/myProject/gene/*In/file.fa