"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 "sort" and "head" commands:

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

5. Search top 10 largest directories with "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 /tmp -type f -mtime +30`   # remove older files

Table of Contents

 About This Book

 Introduction to Ubuntu Systems

 GNOME - Desktop Interface and Environment

 Shell - The Command-Line Interpreter

 Process Management

 Memory 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

 "rar" and "unrar" - Roshal Archive Files

 APT (Advanced Package Tool)

 Network Connection on Ubuntu

 Internet Networking Tools

 SSH Protocol and ssh/scp Commands

 Administrative Tasks

 References

 Full Version in PDF/EPUB