Posted: Fri Jul 04, 2008 8:10 am Post subject: Re: How to find all files between midnight and 08.00 am?
On 2008-07-03, text-dude <newsboost@gmail.com> wrote:
Quote:
Hi,
Question: How to find all files between midnight and 08.00 am? How is
it? Is there any difference on creation date, modification date and
similar?
When I've found these files, I want to change their date manually...
Any help?
If you have GNU find, you can find files based on their age in minutes.
Or with any version of find, you can use touch to create files with time
stamps at midnight and 8 am, and use "find . -newer file1 ! -newer file2"
Posted: Fri Jul 04, 2008 6:10 pm Post subject: Re: How to find all files between midnight and 08.00 am?
On Jul 3, 10:35 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
Quote:
On 2008-07-03, text-dude <newsbo...@gmail.com> wrote:
Hi,
Question: How to find all files between midnight and 08.00 am? How is
it? Is there any difference on creation date, modification date and
similar?
When I've found these files, I want to change their date manually...
Any help?
If you have GNU find, you can find files based on their age in minutes.
I know that, but I'm talking about files that are written on different
days and not just "yesterday", within the last xxxx minutes or
something.
Quote:
Or with any version of find, you can use touch to create files with time
stamps at midnight and 8 am, and use "find . -newer file1 ! -newer file2"
I'm talking about files that are written on different days and not
just "yesterday", within the last xxxx minutes or something, if that
is what you mean. If I understand you correctly, that would need a lot
of touch commands.
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
Posted: Fri Jul 04, 2008 11:10 pm Post subject: Re: How to find all files between midnight and 08.00 am?
On Jul 3, 8:58 pm, text-dude <newsbo...@gmail.com> wrote:
Quote:
Question: How to find all files between midnight and 08.00 am?
How is it? Is there any difference on creation date,
modification date and similar?
Something along the lines of:
find baseDir -ls | awk '$(10) ~ /^0[0-8]:/ { print $(11) }'
should work in general. Otherwise, you can use something like:
find baseDir | xargs ls -ld | awk '$8 ~ /^0[0-8]:/ { print $9 }'
, changing the options to ls so that it displays the different
timestamps. (There is no information as to when the file was
created, but you can determine when it was last modified, when
it was last written, or when its attributes were last modified.)
Note that these fail if any of the filenames includes spaces.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
I'll try on my macintosh tonight and I also have a linux computer, I
want to try it on. In the mean-time, could you please shortly explain
what -printf '%p %CH:%CM\n' means?
I also don't know awk but typed "info awk" and it looks like NF means
"number of fields in the current record", so can you also tell a
little about why the awk-line should work?
Posted: Sat Jul 05, 2008 11:10 pm Post subject: Re: How to find all files between midnight and 08.00 am?
On 4 Jul., 12:05, James Kanze <james.ka...@gmail.com> wrote:
Quote:
On Jul 3, 8:58 pm, text-dude <newsbo...@gmail.com> wrote:
Question: How to find all files between midnight and 08.00 am?
How is it? Is there any difference on creation date,
modification date and similar?
Something along the lines of:
find baseDir -ls | awk '$(10) ~ /^0[0-8]:/ { print $(11) }'
should work in general. Otherwise, you can use something like:
find baseDir | xargs ls -ld | awk '$8 ~ /^0[0-8]:/ { print $9 }'
, changing the options to ls so that it displays the different
timestamps. (There is no information as to when the file was
created, but you can determine when it was last modified, when
it was last written, or when its attributes were last modified.)
This works, thanks... Could somebody please explain why/how it works?
Quote:
Note that these fail if any of the filenames includes spaces.
Actually I have some files where spaces in them. However not too many,
but is there a solution that can deal with spaces too?
Yes, you don't have GNU find installed. (and, btw, "/basedir" was just an
example; you should replace it with the directory on your system where you
want to root your search)
Quote:
I'll try on my macintosh tonight and I also have a linux computer, I
want to try it on.
On the linux computer it will almost certainly work; on the macintosh maybe,
I don't know where the utilities installed there come from.
See below for an approach that probably works on non-GNU systems.
Quote:
In the mean-time, could you please shortly explain
what -printf '%p %CH:%CM\n' means?
For each file found, prints its full pathname, followed by a space ,
followed by the hour and minute of its last status change time (hope that
is what you were looking for). So, the output of the find command is a list
like
/basedir/file1 02:19
/basedir/anotherfile 07:19
/basedir/file with spaces 11:10
....
If you want access time instead of status change time, use %AH:%AM . If you
want modification time, use %TH:%TM .
Quote:
I also don't know awk but typed "info awk" and it looks like NF means
"number of fields in the current record", so can you also tell a
little about why the awk-line should work?
The awk line checks to see if the last field of the line (that containing
the file's change time - or access, or modification -) falls between 00:00
(midnight) and 08:00 (8 am), as you wanted. If that is true, the last field
is removed and the filename is printed.
The list resulting after awk filtering can be further processed. What do you
want to do with the matching files?
On non-GNU systems, you can probably do something like:
find /basedir -type f -exec ls -l \{\} + | awk '$7>="00:00"&& $7<="08:00"
{$1=$2=$3=$4=$5=$6=$7="";sub(/^[[:space:]]*/,"");print}'
and get a similar list. Use "ls -lu" or "ls -lc" to get access/change times
(man ls for the details), instead of the default modification time.
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
Yes, you don't have GNU find installed. (and, btw, "/basedir" was just an
example; you should replace it with the directory on your system where you
want to root your search)
Ok, I also ended up doing that. BTW: I have some kind of "find"-
command installed:
$ which find
/usr/xpg4/bin/find
and: $ man find
Gives:
- find(3C++)
Standard C++ Library
Copyright 1998, Rogue Wave Software, Inc.
NAME
find
- Finds an occurrence of value in a sequence.
Why does it come up with such programming crap, when I wanted to see
the switches of /usr/xpg4/bin/find ?
Quote:
I'll try on my macintosh tonight and I also have a linux computer, I
want to try it on.
On the linux computer it will almost certainly work; on the macintosh maybe,
I don't know where the utilities installed there come from.
See below for an approach that probably works on non-GNU systems.
In the mean-time, could you please shortly explain
what -printf '%p %CH:%CM\n' means?
For each file found, prints its full pathname, followed by a space ,
followed by the hour and minute of its last status change time (hope that
is what you were looking for). So, the output of the find command is a list
like
/basedir/file1 02:19
/basedir/anotherfile 07:19
/basedir/file with spaces 11:10
...
Looks fine. And these things: "%p %CH:%CM" can be looked up with "man
find" on your system (so I know where to look next time, I need such
info) ?
Quote:
If you want access time instead of status change time, use %AH:%AM . If you
want modification time, use %TH:%TM .
Ok. I assume "man find" tells that on a linux system...
Quote:
I also don't know awk but typed "info awk" and it looks like NF means
"number of fields in the current record", so can you also tell a
little about why the awk-line should work?
The awk line checks to see if the last field of the line (that containing
the file's change time - or access, or modification -) falls between 00:00
(midnight) and 08:00 (8 am), as you wanted. If that is true, the last field
is removed and the filename is printed.
awk '$NF>="00:00" && $NF<="08:00" && NF--'
Why do you write "NF" 3 places (what does the last NF do?) ?
It doesn't get confused by the colon?
Quote:
The list resulting after awk filtering can be further processed. What do you
want to do with the matching files?
I just hand in some work and don't want to show that I worked with
these files late in the night.
Quote:
On non-GNU systems, you can probably do something like:
find /basedir -type f -exec ls -l \{\} + | awk '$7>="00:00"&& $7<="08:00"
{$1=$2=$3=$4=$5=$6=$7="";sub(/^[[:space:]]*/,"");print}'
Are there any tutorials for learning to understang that?
Quote:
and get a similar list. Use "ls -lu" or "ls -lc" to get access/change times
(man ls for the details), instead of the default modification time.
It doesn't always work, because sometimes there's a year instead of
time. I assume that everything in 2008 gets written by time but for
everything from 2007, there's no time -- just the year 2007:
sys: ~/ $ ls -l ./maktput.bat
-rwxr-xr-x 1 sname32 sna 182 Jun 1 2007 ./maktput.bat
sys: ~/ $ ls -l ./fig3011_SEQ.png
-rw-r--r-- 1 sname32 sna 16628 Jun 1 16:54 ./
fig3011_SEQ.png
But these are just technicalities... I've done what I should now...
Now I'm just here to "learn something"...
Posted: Sat Jul 05, 2008 11:10 pm Post subject: Re: How to find all files between midnight and 08.00 am?
On Saturday 5 July 2008 14:08, text-dude wrote:
Quote:
Ok, I also ended up doing that. BTW: I have some kind of "find"-
command installed:
$ which find
/usr/xpg4/bin/find
and: $ man find
Gives:
- find(3C++)
Standard C++ Library
Copyright 1998, Rogue Wave Software, Inc.
NAME
find
- Finds an occurrence of value in a sequence.
Why does it come up with such programming crap, when I wanted to see
the switches of /usr/xpg4/bin/find ?
It's not "programming crap". It's just a different implementation of find,
which in this case happens to be less powerful than GNU. And, scrolling
down that page it would probably tell you what options are supported by
that implementation.
Quote:
Looks fine. And these things: "%p %CH:%CM" can be looked up with "man
find" on your system (so I know where to look next time, I need such
info) ?
Yes, man find on linux provides a very detailed explanation of everything.
Quote:
The awk line checks to see if the last field of the line (that containing
the file's change time - or access, or modification -) falls between
00:00 (midnight) and 08:00 (8 am), as you wanted. If that is true, the
last field is removed and the filename is printed.
awk '$NF>="00:00" && $NF<="08:00" && NF--'
Why do you write "NF" 3 places (what does the last NF do?) ?
It doesn't get confused by the colon?
No. $NF represents the last field in the line. "&&" is awk's logical AND
operator. First, we check that the value of $NF is >= than "00:00"; if it
isn't, we already know that we must discard that line, and awk does no
further processing for that line. If it is, we check that its value is also
<= than "08:00". Again, if it isn't, we discard the line and awk stops
processing the line. If we get so far, we know that we want that file, so
we must print the line, but without the last field (which we used for the
test, but we're not interested in anymore). If we decrement the value of NR
(which represents the number of fields in the line), awk thinks that the
line has one field less. Since the overall value of the expression is
nonzero (all the tests have been successful, and NF is still > 0, since it
was at least 2 before), awk prints the (shortened) line.
Quote:
The list resulting after awk filtering can be further processed. What do
you want to do with the matching files?
I just hand in some work and don't want to show that I worked with
these files late in the night.
So you want to change back their access/modification/etc. times to some
value between 8 am and midnight?
Quote:
On non-GNU systems, you can probably do something like:
find /basedir -type f -exec ls -l \{\} + | awk '$7>="00:00"&& $7<="08:00"
{$1=$2=$3=$4=$5=$6=$7="";sub(/^[[:space:]]*/,"");print}'
Are there any tutorials for learning to understang that?
Of course. A good starting point for awk is the GNU awk manual, which covers
the language quite well (and you can read that even if you don't have GNU
awk, since when it describes a GNU awk specific feature it usually says
that).
and get a similar list. Use "ls -lu" or "ls -lc" to get access/change
times (man ls for the details), instead of the default modification time.
It doesn't always work, because sometimes there's a year instead of
time. I assume that everything in 2008 gets written by time but for
everything from 2007, there's no time -- just the year 2007:
sys: ~/ $ ls -l ./maktput.bat
-rwxr-xr-x 1 sname32 sna 182 Jun 1 2007 ./maktput.bat
sys: ~/ $ ls -l ./fig3011_SEQ.png
-rw-r--r-- 1 sname32 sna 16628 Jun 1 16:54 ./
fig3011_SEQ.png
That's probably due to localization issues. Try with
LC_ALL=en_US ls -l filename
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
Posted: Sat Jul 05, 2008 11:10 pm Post subject: Re: How to find all files between midnight and 08.00 am?
On Saturday 5 July 2008 14:27, pk wrote:
Quote:
for the test, but we're not interested in anymore). If we decrement the
value of NR (which represents the number of fields in the line), awk
thinks that the line has one field less. Since the overall value of the
expression is nonzero (all the tests have been successful, and NF is still
0, since it was at least 2 before), awk prints the (shortened) line.
Note that both solutions will fail if you have filenames with >= two
consecutive spaces in them.
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
Posted: Sun Jul 06, 2008 8:10 am Post subject: Re: How to find all files between midnight and 08.00 am?
On 2008-07-05, text-dude <newsboost@gmail.com> wrote:
Quote:
On 4 Jul., 12:05, James Kanze <james.ka...@gmail.com> wrote:
On Jul 3, 8:58 pm, text-dude <newsbo...@gmail.com> wrote:
Question: How to find all files between midnight and 08.00 am?
How is it? Is there any difference on creation date,
modification date and similar?
Something along the lines of:
find baseDir -ls | awk '$(10) ~ /^0[0-8]:/ { print $(11) }'
should work in general. Otherwise, you can use something like:
find baseDir | xargs ls -ld | awk '$8 ~ /^0[0-8]:/ { print $9 }'
, changing the options to ls so that it displays the different
timestamps. (There is no information as to when the file was
created, but you can determine when it was last modified, when
it was last written, or when its attributes were last modified.)
This works, thanks... Could somebody please explain why/how it works?
That's a somewhat vague question. What part of it don't you
understand ?
Here's a tip : when you have a pipe like cmd1 | cmd2 | cmd3 |
cmd4 that you don't understand, it often helps to try cmd1, then
cmd1 | cmd2, then cmd1 | cmd2 | cmd3...
Quote:
Note that these fail if any of the filenames includes spaces.
Actually I have some files where spaces in them. However not too many,
but is there a solution that can deal with spaces too?
You could replace « { print $(11) } » by
« { sub(/^ *([^ ]+ +){10}/, ""); print } ». You'll have to use
/usr/xpg4/bin/awk because Solaris' /usr/bin/awk lacks sub().
This approach will work with file names containing spaces and
tabs but not with file names containing newlines.
--
André Majorel <URL:http://www.teaser.fr/~amajorel/>
"Cette supposition rappelle assez celle de ce prédicateur qui, en
pleine chaire, faisait remarquer à ses fidèles la bonté de Dieu qui
avait placé les rivières auprès des villes." -- Alexandre Dumas
All that means is that you are using Unix, and not some
hacked version; the Posix standard find doesn't have a
-printf option. And of course, you don't need it here
anyway; awk is quite capable of comparing any field, and -ls
is standard for find.
My understanding is that -ls is NOT standard. And,
furthermore, with -ls there is no way to print the file's
access and change time. For those, you have to use find -exec
ls -l{u,c}.
You're right on both counts, although -ls is fairly universal
(since it was present in the original find, and in the System V
version of it).
A lot depends on what the original poster is trying to do. If
he just needs a quick command which gets the job done on the
system he's on, then he should use whatever that system
supports. If he's trying to write a more or less portable shell
script, the issue is more complicated. (And I pity the guys who
have to write scripts which will run on machines they don't have
access to; people sometimes actually install non-standard tools
in /usr/bin, instead of the standard ones, which means that even
setting the path doesn't give you any guarantees.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
All times are GMT + 10 Hours Goto page 1, 2, 3Next
Page 1 of 3
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum