newbie_dev
newbie_dev

Reputation: 57

Bash script for outputting directory details to a file

I am trying to write a simple bash script that will search for files with a certain extension in a directory. Then output all those files with full path in front.

For example, if I have a directory with many different file types, but I want to know the information about those with only the .txt extension. How can I get the output in a new file to look similar to this:

/home/jason/code/test1.txt
/home/jason/code/test2.txt
.
.
.

All I have right now is this, which is not really what I am trying to do, but it is just my attempt at experimentation because I am new:

ls *.txt >prog_list.txt
pwd >pwd.txt
cat pwd.txt prog_list.txt > prog_dir.txt

Upvotes: 0

Views: 348

Answers (4)

naikus
naikus

Reputation: 24472

$>find -name "*.yourext" > myFile.txt

For more information on the find command, type:

$>man find

Upvotes: 1

Kiersten Arnold
Kiersten Arnold

Reputation: 1894

Would something like:


find . -name *.txt -print

do the trick?

Upvotes: 0

Amardeep AC9MF
Amardeep AC9MF

Reputation: 19044

find /home/jason/code -iname "*.txt" > prog_dir.txt

Upvotes: 2

Daenyth
Daenyth

Reputation: 37441

find ~/code -name '*.txt'

Upvotes: 1

Related Questions