[PLUG] Find Issues

Paul Heinlein heinlein at attbi.com
Fri Mar 29 18:30:54 UTC 2002


On Fri, 29 Mar 2002, Michael Montagne wrote:

> I'm running this command to help me find all files that haven't been
> modified in 180 days and delete them.
> find . -type f -mtime +180 -print0|xargs -0 ls -al
> 
> This is what I get:
> total 52
> drwxrwx---    5 ftpuser  ftpgroup     4096 Feb  4 10:12 .
> drwxr-xr-x   34 ftp      ftpgroup     4096 Mar 15 16:41 ..
> -rwxrw----    1 nobody   ftpgroup    28734 Feb  4 10:02 ASA Contact List, 1 Feb 02.pdf
> drwxrwx---    5 nobody   ftpgroup     4096 Feb  5 12:06 Boora
> drwxrwx---   15 nobody   ftpgroup     4096 Jan 16 12:30 Consults
> drwxrwx---    2 nobody   ftpgroup     4096 Nov  9 13:30 Docs
> 
> It seems to me that I should only see files, not directories.  And the
> one file that returned HAS been modified within 180 days.  I noticed
> lots of false positives when files have spaces in their names.  Is this
> a limitation of find?  Can it be overcome?

Heh. Try running it like this:

  find . -type f -mtime +180 -print0|xargs -0 ls -ald

Note the addition of the -d option to the ls invocation. What you'll
notice is that find is returning only one entry: the current directory
(.). Without the -d switch, ls will expand a directory listing, which is
what it's done in your example.

According to the xargs info page, the command associated with xargs (in
this case, ls) will normally "run once even if there is no input." You
can run off that behavior with the --no-run-if-empty (-r) switch, e.g.,

  find . -type f -mtime +180 -print0|xargs -0r ls -al

Obscure, no? :-)

-- Paul Heinlein <heinlein at attbi.com>






More information about the PLUG mailing list