tags:

views:

33

answers:

1

I am trying to put the result of a find command to a text file on a unix bash shell

Using:

find ~/* -name "*.txt" -print > list_of_txt_files.list

However the list_of_txt_files.list stays empty and I have to kill the find to have it return the command prompt. I do have many txt files in my home directory

Alternatively How do I save the result of a find command to a text file from the commandline. I thought that this should work

+2  A: 

The first thing I would do is use single quotes (some shells will expand the wildcards, though I don't think bash does, at least by default), and the first argument to find is a directory, not a list of files:

find ~ -name '*.txt' -print > list_of_txt_files.list

Beyond that, it may just be taking a long time, though I can't imagine anyone having that many text files (you say you have a lot but it would have to be pretty massive to slow down find). Try it first without the redirection and see what it outputs:

find ~ -name '*.txt' -print
paxdiablo
My machine was just running very slow when I tried this command with and without redirecting output to file. The slow machine caused the redirected output to be a lot slower- i.e after a few minutes file was still zero bytes whereas without the output redirection, the *.txt files were listed immediately. Now that my machine has more resources both ways seem as fast.
harijay