Searching for files in Linux with find
The find tool is suitable for searching files under Linux. In this article, you will find information on which options can be used with find.
Search for change times
The following command shows all files in the current directory (and sub-directory), whose content has been modified (modification time) within the last 48 hours (2 x 24h):
find . -mtime -2
Meanings of atime, mtime, ctime:[1]
- atime: Access Time (the file was accessed, e.g., the file was read)
- mtime: Modification Time (the content of the file was changed)
- ctime: Change Time (The inode of the file or the inode of the directory has been changed, for example another owner was configured for the file; the ctime is also updated, when the content of the file changes)
Search for file content
The following command searches all files in the current directory (and sub-directory), whether the text SEARCHSTRING appears in it. This search is useful if the directory contains text files (such as configuration files). The content of PDF files, OpenOffice files, etc. is not searched correctly. The "-i" option in the grep command ensures that the search takes place independently of upper and lower case letters.
find . -type f -print0 | xargs -0 grep -i SEARCHSTRING
Hint: Search file contents more easily with ack-grep (see Searching for files in Linux with ack-grep).
References
- ↑ stat (Unix) (en.wikipedia.org)
|
Author: Werner Fischer Werner Fischer, working in the Knowledge Transfer team at Thomas-Krenn, completed his studies of Computer and Media Security at FH Hagenberg in Austria. He is a regular speaker at many conferences like LinuxTag, OSMC, OSDC, LinuxCon, and author for various IT magazines. In his spare time he enjoys playing the piano and training for a good result at the annual Linz marathon relay.
|
|
Translator: Alina Ranzinger Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.
|


