"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

 Cockpit - Web Portal for Administrator

 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

 Users and Groups

 File Systems

 Block Devices and Partitions

 LVM (Logical Volume Manager)

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Software Package Manager on CentOS - DNF and YUM

 Running Apache Web Server (httpd) on Linux Systems

 Running PHP Scripts on Linux Systems

 Running MySQL Database Server on Linux Systems

 Running Python Scripts on Linux Systems

 vsftpd - Very Secure FTP Daemon

 Postfix - Mail Transport Agent (MTA)

 Dovecot - IMAP and POP3 Server

 Email Client Tools - Mail User Agents (MUA)

 LDAP (Lightweight Directory Access Protocol)

 GCC - C/C++ Compiler

 Graphics Environments on Linux

 Conda - Environment and Package Manager

 Tools and Utilities

 Administrative Tasks

 References

 Full Version in PDF/EPUB