Master Linux Find: 8 Powerful Ways to Locate and Manage Files
This article explains eight practical uses of the Linux find command—including searching by name, type, timestamps, size, permissions, ownership, executing actions on matches, and directory name patterns—providing clear examples and code snippets to help administrators efficiently locate and manage files.
In Linux administration, the find command is essential for locating files and directories based on various criteria.
find . -type f -atime +365 -exec rm -rf {} \;1. Search by name or regular expression
Example: find . -name test.txt Search for all PDF files: find ./yang/books -name "*.pdf" Specify file type for clarity:
find ./yang/books -type f -name "*.pdf"2. Search by file type
Directories: find . -type d -name "yang*" Symbolic links:
find . -type l -name "yang*"3. Search by timestamps
atime – last access time
mtime – last modification time
ctime – last status change time
Find files not accessed for over a year: find . -type f -atime +365 Find files modified exactly 5 days ago: find . -type f -mtime 5 Find files whose ctime is between 5 and 10 days ago:
find . -type f -ctime +5 -ctime -104. Search by size
Size units: b (512‑byte blocks), c (bytes), w (two‑byte words), k (KB), M (MB), G (GB).
Find files between 10 MB and 1 GB:
find . -type f -size +10M -size -1G5. Search by permissions
Find files with permission 777:
find . -type f -perm 7776. Search by ownership
Find files owned by user yang:
find -type f -user yang7. Execute a command on matches
Delete files not accessed for over a year: find . -type f -atime +365 -exec rm -rf {} \; The {} placeholder represents each found file; the command must end with an escaped semicolon \;.
8. Search by directory name
Case‑insensitive search:
find /path/to/search -type d -iname "directory_name"Find the most recently modified directory:
find /path/to/search -type d -printf '%T+ %p
' | sort -n | tail -1Awk quick reference
Awk processes structured text. Basic syntax: awk [options] 'pattern { action }' file Example file file.txt:
name,age,sex,salary
Alice,30,女,9000
Bob,25,男,8000
Carol,35,男,7000
Karry,21,女,5000Print each line: awk '{ print }' file.txt Specify field separator: awk -F ',' '{ print $1, $3 }' file.txt Filter rows where age > 30:
awk -F ',' '$2 > 30 { print $1 }' file.txtSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
