"find" - Search for Files

This section provides a tutorial example on how to use 'find' command to search for files in a directory tree. '-name' and '-size' are 2 commonly used search conditions.

If you have a large directory tree with many files and sub-directories, you can use the "find" command to search for file in the directory tree. Here are some examples:

1. Search files with a file name pattern with the "-name" option:

herong$ find . -name *.zip

... list of *.zip files

2. Search files larger than 100 MB with the "-size" option:

herong$ find . -size +100M -printf '%s %p\n'

3. Search top 10 largest files with the "sort" and "head" commands:

herong$ find . -printf '%s %p\n'| sort -nr | head -10

5. Search top 10 largest directories with the "sort" and "head" commands:

herong$ find . -type d -printf '%s %p\n' | sort -nr | head -10

5. Delete matched files with the "-delete" option:

herong$ find . -name *.tmp -delete

6. More examples with "find" command:

herong$ find . -type f -newermt '2021-07-01'      # files newer than a date
herong$ find . -type f \! -newermt '2021-07-01'   # files older than a date

herong$ find . -type f -mtime -30   # files younger than 30 days
herong$ find . -type f -mtime +30   # files older than 30 days

herong$ rm `find . -type f -mtime +30`   # remove older files

Table of Contents

 About This Book

 Introduction to Linux Systems

 Process Management

Files and Directories

"find" - Search for Files

 "more", "head" and "cat" - Read Files

 "split" and "cat" - Split and Join Files

 Truncate Log Files

 "compress/uncompress" - Compressed *.Z Files

 "gzip/gunzip" - Compressed *.gz Files

 "xz/unxz" - Compressed *.xz or *.lzma Files

 "tar -c" and "tar -x" - Create and Extract Archive Files

 "zip" and "unzip" - Create and Extract ZIP Files

 "Operation not permitted" Error on macOS

 Running Apache HTTP Server (httpd) on Linux Systems

 Running Apache Tomcat on Linux Systems

 Running PHP Scripts on Linux Systems

 Running MySQL Database Server on Linux Systems

 Running Python Scripts on Linux Systems

 Conda - Environment and Package Manager

 GCC - C/C++ Compiler

 OpenJDK - Open-Source JDK

 Graphics Environments on Linux

 SquirrelMail - Webmail in PHP

 Tools and Utilities

 References

 Full Version in PDF/EPUB