find a file

Karl Auer kauer at
Mon Aug 6 12:42:47 UTC 2007

On Mon, 2007-08-06 at 08:21 -0300, Allan Valeriano wrote:

> "locate -R" command, but sometimes it doesn't work.

locate works only on file names and paths, not on content. It also won't
work for files added very recently (i.e., today) because the indexing
happens only once a day. You can force a re-indexing thus:

   sudo /etc/cron.daily/slocate

The indexing deliberately omits indexing some files, for example,
the /proc pseudo-filesystem and various remote-mounted filesystems like
NFS and SMB. It also avoids indexing certain volatile paths,
like /var/spool and /media (which means your attached USB drives won't
get indexed). Look at /etc/updatedb.conf for more info, and possibly
modify it to suit your needs.

> couple of days ago, I wanted to find all the files containing a
> specific word, but couldn't figure out how to use the grep command.

To look in all files with the ".txt" extension in and below the current
directory for the string "help":

   find . -name "*.txt" -exec grep help {} \; -print

Everything after grep and up to the escaped semi-colon is a command that
will be executed on every matching file; "{}" will be replaced in the
command, each time it is executed, by the currently matching filename.

Regards, K.

Karl Auer (kauer at                   +61-2-64957160 (h)                  +61-428-957160 (mob)

More information about the ubuntu-users mailing list