Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

find files from specific date

8 views
Skip to first unread message

Atropo

unread,
Dec 31, 2009, 8:49:47 AM12/31/09
to
Hi all,

I searched similar post about, but some of them i didn't understand
and the others were about file name manipulation. what i want is just
list the files of an specific hour (any minute) from specific date.
i stuck with the hour part.

ls -l | awk ' if (($6=="Dec") && ($7=="29") && ( $8 ~ /08/ )) {print
$0}'

/usr/bin/awk on solaris 9

the last time it worked was

ls -l | awk ' $6=="Dec" && $7=="29" {print $0}'


mop2

unread,
Dec 31, 2009, 9:04:20 AM12/31/09
to

Well, without awk, but is easy to undertand:

$ \ls -l|grep '2009-12-29 11'
drwxr-xr-x 5 web ppp 4096 2009-12-29 11:55 gtkdialog-0.7.20
-rw-r--r-- 1 web ppp 280408 2009-12-29 11:54 gtkdialog-0.7.20.tar.gz
drwx------ 5 web ppp 4096 2009-12-29 11:40 yaf-splash-1.02
-rw-r--r-- 1 web ppp 81391 2009-12-29 11:30 yaf-splash-1.02.tar.gz

$ \ls -l|grep '2009-12-29 11'|tr -s ' '|cut -d' ' -f8-
gtkdialog-0.7.20
gtkdialog-0.7.20.tar.gz
yaf-splash-1.02
yaf-splash-1.02.tar.gz

Ed Morton

unread,
Dec 31, 2009, 9:09:16 AM12/31/09
to
On 12/31/2009 7:49 AM, Atropo wrote:
> Hi all,
>
> I searched similar post about, but some of them i didn't understand
> and the others were about file name manipulation. what i want is just
> list the files of an specific hour (any minute) from specific date.
> i stuck with the hour part.
>
> ls -l | awk ' if (($6=="Dec")&& ($7=="29")&& ( $8 ~ /08/ )) {print

> $0}'
>
> /usr/bin/awk on solaris 9

That's "old, broken awk". Don't use it. Use GNU awk (gawk), New awk (nawk), or
/usr/xpg4/bin/awk on Solaris.

> the last time it worked was
>
> ls -l | awk ' $6=="Dec"&& $7=="29" {print $0}'

You could do it that way with:

ls -l | awk '$6=="Dec" && $7=="29" && $8 ~ /^08/'

but that wouldn't work for older files whose ls -l output is in "month day year"
format rather than "month day time" format so you'd get a more robust solution
using "find -maxdepth 1" with "-mtime" or "-newer" options. man find for details.

Ed.

Atropo

unread,
Dec 31, 2009, 9:10:03 AM12/31/09
to
On 31 dic, 10:04, mop2 <inva...@mail.address> wrote:

> On Thu, 31 Dec 2009 11:49:47 -0200, Atropo <lxvasq...@gmail.com> wrote:
> > Hi all,
>
> > I searched similar post about, but some of them i didn't understand
> > and the others were about file name manipulation. what i want is just
> > list the files of an specific hour (any minute) from specific date.
> > i stuck with the hour part.
>
> > ls -l | awk ' if (($6=="Dec") && ($7=="29") && ( $8 ~ /08/ )) {print

> > $0}'
>
> > /usr/bin/awk on solaris 9
>
> > the last time it worked was
>
> > ls -l | awk ' $6=="Dec" && $7=="29"  {print $0}'
>
> Well, without awk, but is easy to undertand:
>
> $ \ls -l|grep '2009-12-29 11'
> drwxr-xr-x  5 web  ppp          4096 2009-12-29 11:55 gtkdialog-0.7.20
> -rw-r--r--  1 web  ppp        280408 2009-12-29 11:54 gtkdialog-0.7.20.tar.gz
> drwx------  5 web  ppp          4096 2009-12-29 11:40 yaf-splash-1.02
> -rw-r--r--  1 web  ppp         81391 2009-12-29 11:30 yaf-splash-1.02.tar.gz
>
> $ \ls -l|grep '2009-12-29 11'|tr -s ' '|cut -d' ' -f8-
> gtkdialog-0.7.20
> gtkdialog-0.7.20.tar.gz
> yaf-splash-1.02
> yaf-splash-1.02.tar.gz

absolutely right. sometimes you keep spinnin' on the same error, just
because you figure out first

Atropo

unread,
Dec 31, 2009, 9:19:31 AM12/31/09
to

Thanks Ed. i was struggling with find first but their search was
time relative..

Ed Morton

unread,
Dec 31, 2009, 9:20:21 AM12/31/09
to
On 12/31/2009 8:04 AM, mop2 wrote:
> On Thu, 31 Dec 2009 11:49:47 -0200, Atropo <lxva...@gmail.com> wrote:
>
>> Hi all,
>>
>> I searched similar post about, but some of them i didn't understand
>> and the others were about file name manipulation. what i want is just
>> list the files of an specific hour (any minute) from specific date.
>> i stuck with the hour part.
>>
>> ls -l | awk ' if (($6=="Dec") && ($7=="29") && ( $8 ~ /08/ )) {print
>> $0}'
>>
>> /usr/bin/awk on solaris 9
>>
>> the last time it worked was
>>
>> ls -l | awk ' $6=="Dec" && $7=="29" {print $0}'
>>
>
> Well, without awk, but is easy to undertand:
>
> $ \ls -l|grep '2009-12-29 11'
> drwxr-xr-x 5 web ppp 4096 2009-12-29 11:55 gtkdialog-0.7.20
> -rw-r--r-- 1 web ppp 280408 2009-12-29 11:54 gtkdialog-0.7.20.tar.gz
> drwx------ 5 web ppp 4096 2009-12-29 11:40 yaf-splash-1.02
> -rw-r--r-- 1 web ppp 81391 2009-12-29 11:30 yaf-splash-1.02.tar.gz

What shell are you using? I tried bash on cygwin and ksh on Solaris and they
both produce the "monthname dayname time" timestamp.

> $ \ls -l|grep '2009-12-29 11'|tr -s ' '|cut -d' ' -f8-
> gtkdialog-0.7.20
> gtkdialog-0.7.20.tar.gz
> yaf-splash-1.02
> yaf-splash-1.02.tar.gz

That "tr" would corrupt file names that contain consecutive spaces so if you're
relying on file names not containing spaces you can reduce that line to:

$ \ls -l|awk '2009-12-29 11{print $8}'

Regards,

Ed.

mop2

unread,
Dec 31, 2009, 10:04:35 AM12/31/09
to
On Thu, 31 Dec 2009 12:20:21 -0200, Ed Morton <morto...@gmail.com> wrote:

> On 12/31/2009 8:04 AM, mop2 wrote:

>> $ \ls -l|grep '2009-12-29 11'
>> drwxr-xr-x 5 web ppp 4096 2009-12-29 11:55 gtkdialog-0.7.20
>> -rw-r--r-- 1 web ppp 280408 2009-12-29 11:54 gtkdialog-0.7.20.tar.gz
>> drwx------ 5 web ppp 4096 2009-12-29 11:40 yaf-splash-1.02
>> -rw-r--r-- 1 web ppp 81391 2009-12-29 11:30 yaf-splash-1.02.tar.gz
>
> What shell are you using? I tried bash on cygwin and ksh on Solaris and they
> both produce the "monthname dayname time" timestamp.
>

Hi Ed,

$ $0 --version|head -n1;ls --version|head -n1
GNU bash, version 4.0.35(1)-release (i686-pc-linux-gnu)
ls (GNU coreutils) 8.2

$ for s in `\ls /bin/*sh`;do $s -c "printf \"\$0:\t\";ls -l xtctl";done 2>/dev/null
/bin/ash: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
/bin/bash: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
/bin/ksh: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
/bin/rksh: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
/bin/sh: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
/bin/zsh: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl

I don't know why this time format is here, but I like it.


>> $ \ls -l|grep '2009-12-29 11'|tr -s ' '|cut -d' ' -f8-
>> gtkdialog-0.7.20
>> gtkdialog-0.7.20.tar.gz
>> yaf-splash-1.02
>> yaf-splash-1.02.tar.gz
>
> That "tr" would corrupt file names that contain consecutive spaces so if you're
> relying on file names not containing spaces you can reduce that line to:
>
> $ \ls -l|awk '2009-12-29 11{print $8}'
>

Yeah, spaces are ever an inconvenient element to consider (and remember) when
they aren't just separators.
This is a complicator to awk too.
And, if a file contains a space in its name, more than one consecutive are also possible.

pk

unread,
Dec 31, 2009, 10:07:59 AM12/31/09
to
mop2 wrote:

>>> $ \ls -l|grep '2009-12-29 11'
>>> drwxr-xr-x 5 web ppp 4096 2009-12-29 11:55 gtkdialog-0.7.20
>>> -rw-r--r-- 1 web ppp 280408 2009-12-29 11:54 gtkdialog-0.7.20.tar.gz
>>> drwx------ 5 web ppp 4096 2009-12-29 11:40 yaf-splash-1.02
>>> -rw-r--r-- 1 web ppp 81391 2009-12-29 11:30 yaf-splash-1.02.tar.gz
>>
>> What shell are you using? I tried bash on cygwin and ksh on Solaris and
>> they both produce the "monthname dayname time" timestamp.
>>
>
> Hi Ed,
>
> $ $0 --version|head -n1;ls --version|head -n1
> GNU bash, version 4.0.35(1)-release (i686-pc-linux-gnu)
> ls (GNU coreutils) 8.2
>
> $ for s in `\ls /bin/*sh`;do $s -c "printf \"\$0:\t\";ls -l xtctl";done
> 2>/dev/null
> /bin/ash: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
> /bin/bash: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
> /bin/ksh: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
> /bin/rksh: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
> /bin/sh: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
> /bin/zsh: -rwxr-xr-x 1 web ppp 3515 2009-10-16 12:08 xtctl
>
> I don't know why this time format is here, but I like it.

It seems somehow related to localization, eg see

# LC_ALL=C ls -l foo
-rw-r--r-- 1 root root 356 Nov 17 23:14 foo
# LC_ALL=en_US.utf8 ls -l foo
-rw-r--r-- 1 root root 356 2009-11-17 23:14 foo

Bill Marcum

unread,
Dec 31, 2009, 10:08:50 AM12/31/09
to
On 2009-12-31, Ed Morton <morto...@gmail.com> wrote:
> On 12/31/2009 8:04 AM, mop2 wrote:
>> $ \ls -l|grep '2009-12-29 11'
>> drwxr-xr-x 5 web ppp 4096 2009-12-29 11:55 gtkdialog-0.7.20
>> -rw-r--r-- 1 web ppp 280408 2009-12-29 11:54 gtkdialog-0.7.20.tar.gz
>> drwx------ 5 web ppp 4096 2009-12-29 11:40 yaf-splash-1.02
>> -rw-r--r-- 1 web ppp 81391 2009-12-29 11:30 yaf-splash-1.02.tar.gz
>
> What shell are you using? I tried bash on cygwin and ksh on Solaris and they
> both produce the "monthname dayname time" timestamp.
>
It's the ls program, not the shell, that determines the date format, and
that can vary depending on the locale. GNU ls has the "--full-time" option
which always gives the date, time and year. Other versions of ls often
omit the year for files less than 6 months old, and omit the time for older
files or files with a future time stamp.

mop2

unread,
Dec 31, 2009, 10:37:44 AM12/31/09
to

pk,
you are right, tanks:

$ set|grep '^L[AC]'
LANG=en_US
LC_COLLATE=C
LC_CTYPE=fr_FR@euro
$ ls -ld /tmp
drwxrwxrwt 137 root root 40960 2009-12-31 11:46 /tmp/
$ unset LC_CTYPE
$ ls -ld /tmp
drwxrwxrwt 137 root root 40960 2009-12-31 11:46 /tmp/
$ unset LANG
$ ls -ld /tmp
drwxrwxrwt 137 root root 40960 Dec 31 11:46 /tmp/
$

Jon LaBadie

unread,
Dec 31, 2009, 12:33:48 PM12/31/09
to

You could use the -newer option of find and some limit files:

touch -t 200912291059.59 oldest
touch -t 200912291200.00 newest

find <dir> -newer oldest ! -newer newest -ls

stan

unread,
Dec 31, 2009, 4:27:15 PM12/31/09
to
pk wrote:

cygwin recently switched to using LC_ALL=C.UTF-8 as the default system
locale. It's very new and the growing pains are still non-trivial.
It's worse than simply switching a linux distribution to utf-8 because
you have the underlying windows and it's locale intermixing with the
cygwin layer interpolating things on top.

It's been productive as some corner cases have been popping up and
patches pushed back upstream; in a strange sense MS has been
contributing to the improvement of Free software.

Since many apps are inconsistent about checking locale info it's not
surprising that comparing different environments produce different
results. It's actually surprising that anything works at all.

It's somehow comforting to be fighting backspace and delete problems
yet again. It's less frustrating that struggling with the language/api
de jour.

On a portability note, I find myself writing things like

LC_ALL=C sed ...

I'm certainly much more aware of assumptions that I've been blissfully
ignorant of in the past.

0 new messages