View Issue Details

IDProjectCategoryView StatusLast Update
00012591003.1(2016/18)/Issue7+TC2Shell and Utilitiespublic2024-06-11 09:08
Reporterstephane Assigned To 
PrioritynormalSeverityObjectionTypeError
Status ClosedResolutionAccepted As Marked 
NameStephane Chazelas
Organization
User Reference
Sectionfind utility
Page Number2801 (in 2018 edition)
Line Number92124
Interp Status---
Final Accepted TextSee 0001259:0004489
Summary0001259: wrong description for find -atime +7 example
Description>  2. The following command:
>
> find / \( -name tmp -o -name '*.xx' \) -atime +7 -exec rm {} \;
>
> removes all files named tmp or ending in .xx that have not been
> accessed for seven or more 24-hour periods.

It's a classic mistake (caused by a confusing API).

-atime +7 is for files whose age as an *integer* number of days (24-hour periods) is *strictly* greater than 7, so 8 or more days.

I would choose -mtime as an example instead of of -atime as systems these days tend not to update the atime upon every access.

I would also add a ! -type d as rm cannot remove directory files without -r, and find would likely update the access time of those directories (rm would change the mtime).

I would also use + instead of \; to avoid running on rm per file.

Also note that it assumes file names are valid sequences of characters in the locale's charset.
Desired ActionChange to:

      2. The following command:

       find / \( -name tmp -o -name '*.xx' \) ! -type d -mtime +6 -exec rm {} +

      removes all files whose name is tmp or ends in .xx that have not
      been modified in the last seven 24-hour periods.

It's such a common mistake, that it may be worth stressing it. Adding a:

       find / \( -name tmp -o -name '*.xx' \) ! -type d \
         \( -mtime 7 -o -mtime +7 \) -exec rm {} +

      would achieve the same result

Could help, and also to explain the rationale as to why you need -mtime +6 for more than 7 days old.

Tagstc3-2008

Relationships

related to 0001777 Closed Issue 8 drafts inaccuracy in find example 10 

Activities

stephane

2019-06-14 16:53

reporter   bugnote:0004423

There's a similar problem with -size on line 92162:

find / −path /media −prune −o −size +200000 −print

finds file whose size is strictly greater than 100 000 KiB and 511 bytes (are 200001 512-byte units larger or larger). Also note that KB usually refers to 1000 bytes these days. KiB is the IEC way to make it clear we're talking of 1024-based units.

-size +199999

would be 100000 KiB or larger.

For more than 100000 KiB, that would be:

-size +102400000c

nick

2019-07-25 15:08

manager   bugnote:0004489

On page 2801 line 92124-5 change:
    
find / \( −name tmp −o −name '*.xx' \) −atime +7 −exec rm {} \;


    removes all files named tmp or ending in .xx that have not been accessed for seven or more 24-hour periods.

to
  
find / \( −name tmp −o −name '*.xx' \) ! -type d -mtime +7 −exec rm -f {} +


  removes all files named tmp or ending in .xx that have not been modified for more than seven (i.e. eight or more) 24-hour periods.

  
  On page 2802 change lines 92159-92160:
      
the following command searches the file hierarchy for files larger than 100 000 KB without searching any mounted removable media:

      to:
    
the following command searches the file hierarchy for files of size 100 000 KiB or larger without searching any mounted removable media:

          and change "+200000" to "+199999" at line 92162.

Issue History

Date Modified Username Field Change
2019-06-14 16:18 stephane New Issue
2019-06-14 16:18 stephane Name => Stephane Chazelas
2019-06-14 16:18 stephane Section => find utility
2019-06-14 16:18 stephane Page Number => 2801 (in 2018 edition)
2019-06-14 16:18 stephane Line Number => 92124
2019-06-14 16:53 stephane Note Added: 0004423
2019-07-25 15:08 nick Note Added: 0004489
2019-07-25 15:08 nick Interp Status => ---
2019-07-25 15:08 nick Final Accepted Text => See 0001259:0004489
2019-07-25 15:08 nick Status New => Resolved
2019-07-25 15:08 nick Resolution Open => Accepted As Marked
2019-07-25 15:08 nick Tag Attached: tc3-2008
2019-11-20 16:04 geoffclare Status Resolved => Applied
2023-11-27 16:19 nick Relationship added related to 0001777
2024-06-11 09:08 agadmin Status Applied => Closed