Austin Group Defect Tracker

Aardvark Mark III

Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001259 [1003.1(2016)/Issue7+TC2] Shell and Utilities Objection Error 2019-06-14 16:18 2019-06-14 16:53
Reporter stephane View Status public  
Assigned To
Priority normal Resolution Open  
Status New  
Name Stephane Chazelas
User Reference
Section find utility
Page Number 2801 (in 2018 edition)
Line Number 92124
Interp Status ---
Final Accepted Text
Summary 0001259: 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 Action Change 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.

Tags No tags attached.
Attached Files

- Relationships

-  Notes
stephane (reporter)
2019-06-14 16:53

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

- 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

Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker