Problem redirecting search output to file

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

Using:

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

However, list_of_txt_files.list remains empty, and I need to kill find so that it returns the command line. I have many txt files in my home directory

Alternative How to save the result of the find command to a text file from the command line. I thought this should work

+4
source share
2 answers

The first thing I would like to do is use single quotes (some shells will expand wildcards, although 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 

Other than that, it can take a lot of time, although I can't imagine anyone having a lot of text files (you say that you have a lot, but it should be quite massive to slow down find ). Try first without redirecting and see what it outputs:

 find ~ -name '*.txt' -print 
+5
source

You can redirect the output to a file and console together with tee.

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

This will redirect the output to the console and to the file, and therefore, you do not need to guess if the command is actually executing.

+1
source

All Articles