From: Stephane CHAZELAS on
2009-12-3, 10:02(-08), Zinger:
> On Dec 3, 12:56�pm, Lew Pitcher <lpitc...(a)teksavvy.com> wrote:
>> On December 3, 2009 12:36, in comp.unix.shell, Zinger (zmas...(a)gmail.com)
>> wrote:
>>
>> > Hi All,
>>
>> > I want to execute ls <filename> with a switch that should fetch all
>> > files created with that name and are older than one day.
>>
>> "Older" in what sense?
>> Have last been accessed more than one day ago?
>> Have last been modified more than one day ago?
>> Have last had their metadata changed more than one day ago?
>>
>> Remember, Unix files have no inherent "creation date" metadata
>> (although /some/ Unix systems support such information).
[...]
> Thanks. Older than 24 hours i.e. mtime +1

-mtime +1 is older than 48 hours (more than 1 day, so at least 2
days). It's -mtime +0 for more than 24 hours.

> Note I do not want to use find as it searches recursively and I want
> to just restrict to pwd.
[...]


Use ! -name . -prune, or the GNU -maxdepth option.

Or use zsh:

ls -ld -- foo.*(m+0)

lists the at least 1 day old files.

~$ ls -l a
-rw-r--r-- 1 chazelas chazelas 642469 Dec 1 22:10 a
~$ date
Thu Dec 3 19:46:17 GMT 2009
~$ find a -mtime +1
~$ find a -mtime +0
a
~$ ls -ld a(m+0)
-rw-r--r-- 1 chazelas chazelas 642469 Dec 1 22:10 a
~$ ls -ld a(m+1)
zsh: no matches found: a(m+1)
~$ ls -ld a(mh+23)
-rw-r--r-- 1 chazelas chazelas 642469 Dec 1 22:10 a

(more than 23 hours, so at least 24)

--
St�phane
From: Maxwell Lol on
Zinger <zmasood(a)gmail.com> writes:

> I do not want to use find as if I do find . -name "capz*", it
> recursively finds it in subdriectories as well.

Just as another option, you can create a file once a day using cron,
and then later list all files newer than that file. Heck, you can even
do a simple ls by time, and chop off all files

ls -t | sed -n '/MARKFILE/{d;q}'

From: Kaz Kylheku on
On 2009-12-03, Zinger <zmasood(a)gmail.com> wrote:
> On Dec 3, 12:47 pm, Bill Marcum <marcumb...(a)bellsouth.net> wrote:
>> On 2009-12-03, Zinger <zmas...(a)gmail.com> wrote:> Hi All,
>>
>> > I want to execute ls <filename> with a switch that should fetch all
>> > files created with that name and are older than one day.
>>
>> > Pls help
>>
>> There is no creation time in Unix.
>> find . -name foobar  \( -mtime +1 -o -ctime +1 -o -atime +1 \) -print
>
> Hi All,
>
> I apologize if I have not put the question correctly.
>
> In a particular directory there are files with names as following:-
>
> capz.1234
> capz.3456
> capz.6789
>
> With ls I want to fetch files that have time stamp of "not within the
> last 24 hours".
>
> I do not want to use find as if I do find . -name "capz*", it
> recursively finds it in subdriectories as well.

RTFM!

Firstly, GNU find has -mindepth and -maxdepth, which are useful.
If you have GNU find, you can simply ``find . -maxdepth 1 ...''
and find won't recurse into subdirectories. Done!

If we restrict ourselves to POSIX find, what we can do is prevent find
from descending into directories by including the clause ``-type d
-prune'' disjunctively.

For instance:

# Not quite right!

# find objects of type f (regular files) and print them,
# or find directories and prune them from the search

find . -type f -print -o -type d -prune # <- wrong

Now the above won't do anything because find finds the . directory
first. It does what it's told and prunes it. Several
ways to fix that. Expand the files yourself. Now
find is not really finding anything any longer:

find .* * -type f -print -o -type d -prune

However, even though find is not doing the work of finding
anything, it's still applying the rules. We can add
the modification time criterion:

find .* * -type f -mtime +1 -print \
-o -type d -prune

Another way to get find to visit the . directory instead of pruning it
is to force a match for the name '.' on the left hand side of the -o.
The -o operator is a short-circuited or; if the left hand side matches,
the right side is not evaluated, and so the pruning side effect does not
take place.

# visit the current directory, but don't print it;
# and visit the files, printing those, but don't
# recurse into subdirectories.

find . \( -type f -print -o -name '.' \) -o -type d -prune

Now adding the modification time at least 24 hours ago test:

find . \( -type f -mtime +1 -print \
-o -name '.' \) \
-o -type d -prune
From: zhang towel on
On Dec 4, 2:14 pm, Kaz Kylheku <kkylh...(a)gmail.com> wrote:
> On 2009-12-03, Zinger <zmas...(a)gmail.com> wrote:
>
> touch -t day file_tmp
ls <filename> | find -newer !file_tmp
>
>
>
> > On Dec 3, 12:47 pm, Bill Marcum <marcumb...(a)bellsouth.net> wrote:
> >> On 2009-12-03, Zinger <zmas...(a)gmail.com> wrote:> Hi All,
>
> >> > I want to execute ls <filename> with a switch that should fetch all
> >> > files created with that name and are older than one day.
>
> >> > Pls help
>
> >> There is no creation time in Unix.
> >> find . -name foobar  \( -mtime +1 -o -ctime +1 -o -atime +1 \) -print
>
> > Hi All,
>
> > I apologize if I have not put the question correctly.
>
> > In a particular directory there are files with names as following:-
>
> > capz.1234
> > capz.3456
> > capz.6789
>
> > With ls I want to fetch files that have time stamp of "not within the
> > last 24 hours".
>
> > I do not want to use find as if I do find . -name "capz*", it
> > recursively finds it in subdriectories as well.
>
> RTFM!
>
> Firstly, GNU find has -mindepth and -maxdepth, which are useful.
> If you have GNU find, you can simply ``find . -maxdepth 1 ...''
> and find won't recurse into subdirectories. Done!
>
> If we restrict ourselves to POSIX find, what we can do is prevent find
> from descending into directories by including the clause ``-type d
> -prune'' disjunctively.
>
> For instance:
>
>   # Not quite right!
>
>   # find objects of type f (regular files) and print them,
>   # or find directories and prune them from the search
>
>   find . -type f -print  -o -type d -prune  # <- wrong
>
> Now the above won't do anything because find finds the . directory
> first. It does what it's told and prunes it. Several
> ways to fix that. Expand the files yourself. Now
> find is not really finding anything any longer:
>
>   find .* * -type f -print  -o -type d -prune  
>
> However, even though find is not doing the work of finding
> anything, it's still applying the rules. We can add
> the modification time criterion:
>
>   find .* * -type f -mtime +1 -print \
>             -o -type d -prune  
>
> Another way to get find to visit the . directory instead of pruning it
> is to force a match for the name '.' on the left hand side of the -o.
> The -o operator is a short-circuited or; if the left hand side matches,
> the right side is not evaluated, and so the pruning side effect does not
> take place.
>
>   # visit the current directory, but don't print it;
>   # and visit the files, printing those, but don't
>   # recurse into subdirectories.
>
>   find . \( -type f -print -o -name '.' \) -o -type d -prune  
>
> Now adding the modification time at least 24 hours ago test:
>
>   find . \( -type f -mtime +1 -print \
>              -o -name '.' \) \
>          -o -type d -prune

From: Ben Bacarisse on
Bill Marcum <marcumbill(a)bellsouth.net> writes:

> On 2009-12-03, Zinger <zmasood(a)gmail.com> wrote:
<snip>
>> I want to execute ls <filename> with a switch that should fetch all
>> files created with that name and are older than one day.
<snip>
> There is no creation time in Unix.

Maybe not now, but there was. The original Unix stored a creation
time in a file's inode.

--
Ben.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5
Prev: Strip path to get filename
Next: touch to strip extension.