GNU Find Utility Manual
Total Page:16
File Type:pdf, Size:1020Kb
Finding Files Edition 4.5.11-git, for GNU find version 4.5.11-git 17 November 2012 by David MacKenzie and James Youngman This file documents the GNU utilities for finding files that match certain criteria and per- forming various operations on them. Copyright c 1994, 1996, 1998, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”. i Table of Contents 1 Introduction..................................... 1 1.1 Scope .......................................................... 1 1.2 Overview ...................................................... 2 1.3 find Expressions ............................................... 3 2 Finding Files .................................... 5 2.1 Name .......................................................... 5 2.1.1 Base Name Patterns ....................................... 5 2.1.2 Full Name Patterns........................................ 5 2.1.3 Fast Full Name Search..................................... 7 2.1.4 Shell Pattern Matching .................................... 8 2.2 Links .......................................................... 9 2.2.1 Symbolic Links ............................................ 9 2.2.2 Hard Links............................................... 10 2.3 Time ......................................................... 11 2.3.1 Age Ranges .............................................. 11 2.3.2 Comparing Timestamps .................................. 12 2.4 Size........................................................... 13 2.5 Type ......................................................... 14 2.6 Owner ........................................................ 15 2.7 File Mode Bits ................................................ 15 2.8 Contents ...................................................... 17 2.9 Directories .................................................... 17 2.10 Filesystems .................................................. 19 2.11 Combining Primaries With Operators ........................ 20 3Actions......................................... 21 3.1 Print File Name............................................... 21 3.2 Print File Information......................................... 21 3.2.1 Escapes .................................................. 22 3.2.2 Format Directives ........................................ 23 3.2.2.1 Name Directives ..................................... 23 3.2.2.2 Ownership Directives ................................ 23 3.2.2.3 Size Directives....................................... 24 3.2.2.4 Location Directives .................................. 24 3.2.2.5 Time Directives ..................................... 24 3.2.2.6 Other Directives..................................... 25 3.2.2.7 Reserved and Unknown Directives ................... 25 3.2.3 Time Formats ............................................ 25 3.2.3.1 Time Components ................................... 25 3.2.3.2 Date Components ................................... 26 3.2.3.3 Combined Time Formats ............................ 26 ii 3.2.3.4 Formatting Flags .................................... 27 3.3 Run Commands............................................... 27 3.3.1 Single File ............................................... 27 3.3.2 Multiple Files ............................................ 28 3.3.2.1 Unsafe File Name Handling.......................... 29 3.3.2.2 Safe File Name Handling ............................ 30 3.3.2.3 Unusual Characters in File Names ................... 30 3.3.2.4 Limiting Command Size ............................. 32 3.3.2.5 Controlling Parallelism .............................. 32 3.3.2.6 Interspersing File Names ............................ 34 3.3.3 Querying................................................. 35 3.4 Delete Files ................................................... 35 3.5 Adding Tests.................................................. 36 4 File Name Databases.......................... 37 4.1 Database Locations ........................................... 37 4.2 Database Formats............................................. 37 4.2.1 LOCATE02 Database Format ............................ 38 4.2.2 Sample LOCATE02 Database ............................ 38 4.2.3 slocate Database Format ................................. 39 4.2.4 Old Database Format .................................... 39 4.3 Newline Handling ............................................. 40 5 File Permissions ............................... 41 5.1 Structure of File Permissions .................................. 41 5.2 Symbolic Modes .............................................. 42 5.2.1 Setting Permissions ...................................... 42 5.2.2 Copying Existing Permissions ............................ 43 5.2.3 Changing Special Permissions ............................ 43 5.2.4 Conditional Executability ................................ 44 5.2.5 Making Multiple Changes ................................ 44 5.2.6 The Umask and Protection ............................... 45 5.3 Numeric Modes ............................................... 45 6 Date input formats ............................ 47 6.1 General date syntax ........................................... 47 6.2 Calendar date items........................................... 48 6.3 Time of day items............................................. 49 6.4 Time zone items .............................................. 50 6.5 Day of week items ............................................ 50 6.6 Relative items in date strings.................................. 50 6.7 Pure numbers in date strings .................................. 51 6.8 Seconds since the Epoch ...................................... 52 6.9 Specifying time zone rules ..................................... 52 6.10 Authors of parse_datetime.................................. 53 iii 7 Configuration .................................. 54 7.1 Leaf Optimisation ............................................. 54 7.2 d type Optimisation .......................................... 54 7.3 fts ............................................................ 54 8 Reference ...................................... 55 8.1 Invoking find................................................. 55 8.1.1 Filesystem Traversal Options ............................. 55 8.1.2 Warning Messages........................................ 56 8.1.3 Optimisation Options .................................... 56 8.1.4 Debug Options ........................................... 57 8.1.5 Find Expressions ......................................... 57 8.2 Invoking locate .............................................. 57 8.3 Invoking updatedb ............................................ 60 8.4 Invoking xargs ............................................... 61 8.4.1 xargs options............................................. 62 8.4.2 Invoking the shell from xargs ............................. 64 8.5 Regular Expressions........................................... 65 8.5.1 ‘findutils-default’ regular expression syntax ........... 65 8.5.2 ‘awk’ regular expression syntax ........................... 66 8.5.3 ‘egrep’ regular expression syntax ......................... 67 8.5.4 ‘emacs’ regular expression syntax ......................... 68 8.5.5 ‘gnu-awk’ regular expression syntax....................... 69 8.5.6 ‘grep’ regular expression syntax .......................... 70 8.5.7 ‘posix-awk’ regular expression syntax .................... 71 8.5.8 ‘posix-basic’ regular expression syntax .................. 72 8.5.9 ‘posix-egrep’ regular expression syntax .................. 72 8.5.10 ‘posix-extended’ regular expression syntax ............. 73 8.6 Environment Variables ........................................ 74 9 Common Tasks ................................ 76 9.1 Viewing And Editing.......................................... 76 9.2 Archiving ..................................................... 76 9.3 Cleaning Up .................................................. 77 9.4 Strange File Names ........................................... 78 9.5 Fixing Permissions ............................................ 78 9.6 Classifying Files............................................... 79 iv 10 Worked Examples ............................ 80 10.1 Deleting Files ................................................ 80 10.1.1 The Traditional Way .................................... 80 10.1.2 Making Use of xargs.................................... 81 10.1.3 Unusual characters in filenames ......................... 81 10.1.4 Going back to -exec .................................... 81 10.1.5 A more secure version of -exec.......................... 82 10.1.6 Using the -delete action ............................... 83 10.1.7 Improving things still further ............................ 83 10.1.8 Conclusion .............................................. 84 10.2 Copying A Subset of Files .................................... 84 10.3 Updating A Timestamp File ................................. 85 10.3.1 Updating the Timestamp The Wrong Way............... 85 10.3.2 Using the test utility to compare timestamps ............ 85 10.3.3 A combined approach ..................................