harijay
harijay

Reputation: 11883

Problem redirecting output of find to a file

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

Upvotes: 13

Views: 45533

Answers (3)

lkreinitz
lkreinitz

Reputation: 310

Here is what worked for me

find . -name '*.zip' -exec echo {} \\; > zips.out

Upvotes: 2

Prashant Nidgunde
Prashant Nidgunde

Reputation: 435

You can redirect output to a file and console together by using tee.

find ~ -name '*.txt' -print | tee result.log

This will redirect output to console and to a file and hence you don't have to guess whether if command is actually executing.

Upvotes: 9

paxdiablo
paxdiablo

Reputation: 881403

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

Upvotes: 18

Related Questions