How to search for old files on Linux?

Asked

Viewed 266 times

1

I need to use the command tail -f, to do a search on logs bygones. I know there’s a tail -f | grep "".

But I don’t know how to find the old ones with the parameter I want. Can someone help me?

2 answers

1

To search for files that have a certain age, you can use the grep in conjunction with the find through the option -mtime to carry out the search.

The example below will look for the word foo in all files modified until 20 days ago in the current directory.

find . -type f -mtime -20 -print0 | xargs -0 grep -li 'foo'

To search for modified files there is n minutes ago use -mmin instead of -mtime.

0

I’m not sure I understand the question. You need to search for something in old logs?

If this is the case, you should not need Tail -f, it is only useful to track logs that are running at this time (for example, Voce needs to see some Exception while browsing your site).

For old files (which are no longer changed), only grep should work.

Going to the directory of the Voce logs can run

grep -i 'oquevoceprocura' *

(o -i is not to differentiate capital from minuscules)

This will fetch this string in all files in the current directory.

More about the grep:

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_02.html

http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/

  • I saw the question of -i. and I appreciate the help. I was getting it wrong! Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.