This question may be silly and super easy for linux connaisseurs, but I was just wondering, for instance, I want to use the >find command to search for a file and send the results to a text file, anyone knows how I can do this? Im using lucid lynx btw
|
feedback
|
migrated from stackoverflow.com Nov 26 '10 at 9:05
This question came from our site for professional and enthusiast programmers.
|
You want to use redirection for this.
| |||||||||||||
feedback
|
|
IF you just want to find certain files. As Ignacio answered:
If you want to find certain files, and output the content of these files.
| |||||
feedback
|
|
You could run the commands by Python, using it's subprocess module, and save the results in text files. Redirection also works(as shown by @Ignacio), but contents of the file will over-written every time the command is run. | |||||
feedback
|
|
Seems your need is to find the file by FILENAME rather than some other criteria. There's a much better utility for this than 'find' available, called 'locate'. It uses the locate database to find files by name, so it's much faster than searching over the filesystem. First, run 'updatedb' as root to ensure your locate database is up-to-date - and possibly add a CRON job to run that nightly if there isn't one already. Then, use 'locate filename' or 'locate -r regexp' to locate files. I mention the second option because 'locate abc.log' will find for example abc.log.1 and abc.log.1.gz and whatever else matches. So, 'locate -r abc.log\$' in this case will locate ONLY files named abc.log Finally, as has already been mentioned, to put the resulting output of the command into a file, use > as in:
| |||
|
feedback
|
|
Use a pipe, e.g.
| |||||||||||
feedback
|
