Welcome to Coding : Sécurité Programmation Réseaux

Search   in  

 Create an Account Home | Submit News Your Account Content | Topics | Top 10  


Accueil
· Home
· Listing des Articles
· Top 10
· Repository des Exploits

Les sujets / parties
· C / C ++
· Visual Basic
· Asm
· Reseaux
· Java
· Securite
· Divers

Utile
· Listing des Articles

· Telecharger
· Le Forum
· Liens
· Proposer un article

Top20 des Downloads
· 1: Etude des reseaux generalites et protocoles
· 2: Cheval de troie en VB avec sources
· 3: Netcat 1.1
· 4: Keylogger
· 5: Etudes des reseaux hauts debits architectures et protocoles
· 6: Ecoute de port
· 7: Etude du Smart Spoofing
· 8: Win Packet Capture Utils
· 9: Tutorial on Traffic Interception on Switched Lan using ARP spoofing
· 10: Cours de C

User Info
Welcome, Anonymous
Nickname
Password
(Register)
Membership:
Latest: longjohn
New Today: 0
New Yesterday: 2
Overall: 2216

People Online:
Visitors: 29
Members: 0
Total: 29

  
Coding : Sécurité Programmation Réseaux: Forums

Coding :: View topic - How to find all files between midnight and 08.00 am?
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to find all files between midnight and 08.00 am?
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    Coding Forum Index -> Scripting
View previous topic :: View next topic  
Author Message
text-dude
Guest





PostPosted: Fri Jul 04, 2008 8:10 am    Post subject: How to find all files between midnight and 08.00 am? Reply with 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?
Back to top
Bill Marcum
Guest





PostPosted: Fri Jul 04, 2008 8:10 am    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

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"
Back to top
text-dude
Guest





PostPosted: Fri Jul 04, 2008 6:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

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.
Back to top
pk
Guest





PostPosted: Fri Jul 04, 2008 6:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

On Thursday 3 July 2008 20:58, text-dude 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...

You can do something like (with GNU find)

find /basedir -type f -printf '%p %CH:%CM\n' |
awk '$NF>="00:00" && $NF<="08:00" && NF--'

to get a list of such files.

--
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.
Back to top
James Kanze
Guest





PostPosted: Fri Jul 04, 2008 11:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

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
Back to top
Bill Marcum
Guest





PostPosted: Sat Jul 05, 2008 8:11 am    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

On 2008-07-04, text-dude <newsboost@gmail.com> wrote:
Quote:


On Jul 3, 10:35 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
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.

Then you could parse the output of ls -l or stat.
Back to top
text-dude
Guest





PostPosted: Sat Jul 05, 2008 11:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

On 4 Jul., 09:52, pk <p...@pk.invalid> wrote:
Quote:
On Thursday 3 July 2008 20:58, text-dude 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...

You can do something like (with GNU find)

find /basedir -type f -printf '%p %CH:%CM\n' |
awk '$NF>="00:00" && $NF<="08:00" && NF--'

to get a list of such files.

It doesn't work here:
uname -a
SunOS bohr 5.10 Generic_125100-10 sun4u sparc SUNW,Sun-Fire

$ find /basedir -type f -printf '%p %CH:%CM\n' | awk '$NF>="00:00"
&& $NF<="08:00" && NF--'
find: bad option -printf
find: [-H | -L] path-list predicate-list


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?
Back to top
text-dude
Guest





PostPosted: Sat Jul 05, 2008 11:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

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?
Back to top
pk
Guest





PostPosted: Sat Jul 05, 2008 11:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

On Saturday 5 July 2008 11:55, text-dude wrote:

Quote:
On 4 Jul., 09:52, pk <p...@pk.invalid> wrote:
On Thursday 3 July 2008 20:58, text-dude 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...

You can do something like (with GNU find)

find /basedir -type f -printf '%p %CH:%CM\n' |
awk '$NF>="00:00" && $NF<="08:00" && NF--'

to get a list of such files.

It doesn't work here:
uname -a
SunOS bohr 5.10 Generic_125100-10 sun4u sparc SUNW,Sun-Fire

$ find /basedir -type f -printf '%p %CH:%CM\n' | awk '$NF>="00:00"
&& $NF<="08:00" && NF--'
find: bad option -printf
find: [-H | -L] path-list predicate-list

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.
Back to top
text-dude
Guest





PostPosted: Sat Jul 05, 2008 11:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

On 5 Jul., 12:47, pk <p...@pk.invalid> wrote:

Quote:
 $  find /basedir -type f -printf '%p %CH:%CM\n' |  awk '$NF>="00:00"
&& $NF<="08:00" && NF--'
find: bad option -printf
find: [-H | -L] path-list predicate-list

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"...
Back to top
pk
Guest





PostPosted: Sat Jul 05, 2008 11:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

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).

http://www.gnu.org/software/gawk/manual/gawk.html

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

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.
Back to top
pk
Guest





PostPosted: Sat Jul 05, 2008 11:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

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.
Back to top
pk
Guest





PostPosted: Sat Jul 05, 2008 11:10 pm    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

On Saturday 5 July 2008 14:08, text-dude wrote:

Quote:
Why does it come up with such programming crap, when I wanted to see
the switches of /usr/xpg4/bin/find ?

Sorry, I misread your output. Ok, it's programming stuff, you're correct. To
get find's man page, try

man 1 find

if that doesn't work, your system probably does not have a man page for find
installed. You may also try

find -h
find --help

to get an usage summary, but they are not guaranteed to work either.
Back to top
Andre Majorel
Guest





PostPosted: Sun Jul 06, 2008 8:10 am    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

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
Back to top
James Kanze
Guest





PostPosted: Mon Jul 07, 2008 4:10 am    Post subject: Re: How to find all files between midnight and 08.00 am? Reply with quote

On Jul 6, 7:03 pm, pk <p...@pk.invalid> wrote:
Quote:
On Sunday 6 July 2008 18:49, James Kanze wrote:

$ find /basedir -type f -printf '%p %CH:%CM\n' | awk '$NF>="00:00"
&& $NF<="08:00" && NF--'
find: bad option -printf
find: [-H | -L] path-list predicate-list

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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Coding Forum Index -> Scripting All times are GMT + 10 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
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

Powered by phpBB © 2001, 2005 phpBB Group
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.47 Seconds