LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   find -name and moving to file (https://www.linuxquestions.org/questions/linux-general-1/find-name-and-moving-to-file-355868/)

mijohnst 08-22-2005 01:17 PM

find -name and moving to file
 
I'm trying to do something that I know worked before, but I must have forgotten a step or something.

I want to search some directories for specific file and output it to a file as a list. I thought it would be something like this:

find . -name *.tmp -print >> /tmp/list.txt

When I type this it prints a list of the files it finds on the screen, but nothing in the file I'm redirecting to. I've even tried:

find . -name *.tmp | printf "%s/n" >>/tmp/list.txt

I've had no luck. What am I doing wrong? Sorry, I know this is a basic tool...

zedmelon 08-22-2005 01:43 PM

-name ?
 
find ./ -name temp* >> /tmp/listit

just worked for me. Your example doesn't include the "-name" option, but i'm guessing it's a typo because your subject does.

If that doesn't work, try escaping the star since it's at the front of the search string.

mijohnst 08-22-2005 02:05 PM

Opps... yeah, I have been using -name and it still didn't work.

The strange thing about it is that when I leave off the print command, it just prints each file down the screen... I just cannot get it to copy into a file.

mijohnst 08-22-2005 02:42 PM

hey zedmelon... your suggestion worked. It will list the files if I do a:

find ./ -name temp* >> /tmp/list.txt

Makes me wonder how you'd do a find on files with a certain extension though.

txtedmacs 08-26-2005 02:47 PM

Re: find -name and moving to file
 
Quote:

Originally posted by mijohnst
I want to search some directories for specific file and output it to a file as a list. I thought it would be something like this:

find . -name *.tmp -print >> /tmp/list.txt

When I type this it prints a list of the files it finds on the screen, but nothing in the file I'm redirecting to. I've even tried:

find . -name *.tmp | printf "%s/n" >>/tmp/list.txt

I've had no luck. What am I doing wrong? Sorry, I know this is a basic tool...

If you are just trying to get the list of files into another file, why are you wasting your time with the find command?

Use list:

ls -l *.tmp >> /tmp/list.txt

I also do something that may not be required with the find command. I use single quotes around the search string: '*.tmp', nonetheless if you just need the list use the list command. It's both simple and quick.

Hope I have not misread your intent.

mijohnst 08-26-2005 04:59 PM

Thanks txtedmacs! That works too... lol

If it sounds to easy, it's because it is. :)


All times are GMT -5. The time now is 09:58 PM.