Grep is your friend :-)

Let’s say you have a running server and you notice that something in the server is not working well, so you want to search a log file for errors:

grep "error" somelogfile.log

This returned no results. This could be because grep being case-sensitive, let’s add the case-insensitivity flag:

grep –i "error" somelogfile.log

If the word “error” in any casing appears in the log file, you’ll see the relevant lines in the console. This is not the only way for the program to inform you there’s a problem, there are other words which might be relevant. You don’t want to search for them one by one:

grep –Ei "error|blocked|panic" somelogfile.log

The “E” flag indicates the use of regular expressions, which will allow you to use the pipe sign, dollar sign and other useful regex.

Now, you finally get the result you wanted, but you can only see one line of it and you want to know what it’s all about, so you can do this:

grep –A 10 –B 20 "Error" somelogfile.log

Find file by access, change or modify time.

How to find files that were last modified 10 days ago, use:
root# find / -iname "*" -mtime -10 -print

How to find files that were last modified 10 days ago and for each of them do stat:
root# find / -iname "*" -mtime -10 -exec stat {} ;

How to find files that were last modified 24 hours ago and move them to some directory:
root# find / -name "*.png" -mmin -1440 -exec mv {} some_directory ;

How to find all files in your home directory modified or created today. By default, find counts days from midnight, so an age of zero means today.
user~> find ~ -type f -mtime 0

Find all file belongs to group “ftpusers” in /home directory, enter:
root# find /home -group ftpusers

Find all file belongs to user root in / directory
root# find / -user root

Find files and directories that are not owned by user, use:
find ~ ! -user ${USER}

Find anything in the current user’s directory that is not owned by that user and fix the permissions:
find ~ ! -user $USER -exec sudo chown ${USER}:"{}" ;

Find file and redirect errors to /dev/null
find / -name "apache2" -print 2>/dev/null


Other options:
access (read the file’s contents) – atime
change the status (modify the file or its attributes) – ctime
modify (change the file’s contents) – mtime

How do I find text within files in Linux ?

This document is for users looking for information about finding text within one or more files on their computer. One of the easiest methods of locating text contained within a file on a computer running Linux is to use the grep command. Below is a basic example of a command used to locate any file containing the word “linux”.

find / -type f -exec grep -H 'linux' {} \;

Added by the LiNiO long before his died:
try also:
fgrep -rw linux path