Operating System - HP-UX
1834926 Members
2552 Online
110071 Solutions
New Discussion

Re: find files of certain date

 
Fuad_1
Regular Advisor

find files of certain date

Hi,

I have many files with different creation date, I want to find and copy files of date 19 Dec, please help.
Set goals, and work to achieve them
18 REPLIES 18
MarkSyder
Honored Contributor

Re: find files of certain date

Hi Fuad,

Assuming you're in the correct directory already, ll|grep "Dec 19" will identify the files for you.

If you need to search sub-directories, you will need to use the find command. If I have any spare moments I'll play about with it to try to find the format you need.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Robert-Jan Goossens
Honored Contributor

Re: find files of certain date

Hi,

# find /dir -exec ls -l {}\; | grep "Dec 19" | while read LINE
do
cp $LINE /dir
done

Robert-Jan

Dietmar Konermann
Honored Contributor

Re: find files of certain date

You cannot check for the creation date. Only for last access (atime), last modification (mtime) or last file status change (ctime).

You could look for the -mtime option of find...

-mtime n
True if the file modification time subtracted from the initialization time is n-1 to n multiples of 24 h. The initialization time shall be a time between the invocation of the find utility and the first access by that invocation of the find utility to any file specified in its path operands.

Try e.g.:

# find -mtime 3

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Fuad_1
Regular Advisor

Re: find files of certain date

with -mtime 3 it gives files for 19 and 20 Dec, I do need only 19
Set goals, and work to achieve them
MarkSyder
Honored Contributor

Re: find files of certain date

-mtime 3|grep -v "Dec 20"

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Dietmar Konermann
Honored Contributor

Re: find files of certain date

Well, -mtime 3 works out the difference between the current time and the file's modification time.

Assuming, your file names don't contain " Dec 19 ", this should work...

# ls -lR | grep '^-.* Dec 19 '

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Fuad_1
Regular Advisor

Re: find files of certain date

It does not work, I want a complete command to find files of specific date and copy them to other dir.
Set goals, and work to achieve them
Michael Schulte zur Sur
Honored Contributor

Re: find files of certain date

Hi,

there is a slight chance to get the creation date, however no way of being sure with:
ls -lc
This shows the last modification of the inode, so if ther was no chmod or so, then this reflects the creation time.

ls -lcR | grep ' Dec 19 ' | xargs -I{} -n1 cp -p "{}" /dir/

greetings,

Michael

Robert-Jan Goossens
Honored Contributor

Re: find files of certain date

Hi,

# find /dir -exec ls -l {} \; | grep "Dec 19" |awk '{ print $9 }' | while read LINE do
cp /$LINE /dir
done

RJ
MarkSyder
Honored Contributor

Re: find files of certain date

Have you tried Robert-Jan's solution from early on in this thread? I haven't tried it, but it looks as if it should work.

Two points: you should replace the first occurrence of /dir with the directory where the search is to start and the second one with the directory you want the files copied to. If you want to keep ownership, group, and permissions, use cp -p.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Robert-Jan Goossens
Honored Contributor

Re: find files of certain date

Marc + Fuad,

The first does not work, the second one will work if you change the search directory and the destination directory.

Regards,
Robert-Jan
Bakos György
Super Advisor

Re: find files of certain date

A litle bit offtopic:
What is when I want to do something (delete, copy...) with the files before(acces time, modify...) dec 20

This selects dec 20
find -mtime 3|grep -v "Dec 20"
Michael Schulte zur Sur
Honored Contributor

Re: find files of certain date

Hi,

calcualte the number of days and then
find ./ -mtime +days

greetings,

michael
Robert-Jan Goossens
Honored Contributor

Re: find files of certain date

Bakos,
You mean older then 3 days ?

# find . -mtime +3 -exec ls -l {} ;\

copy change ls -l --> "cp -r" or "mv" or "rm -r"

Ps please start your own thread (:-)
Fuad_1
Regular Advisor

Re: find files of certain date

not older than 3 days, I want files ony in specific date. All the above does not work, please help.
Set goals, and work to achieve them
Robert-Jan Goossens
Honored Contributor

Re: find files of certain date

Fuad,

# find . /tmp -exec ls -l | grep "Dec 19" | awk '{ print $9 }' | while read LINE
do
cp $LINE /DESTANATION_DIR
done

do not use copy and paste !!!!
Robert-Jan
Bakos György
Super Advisor

Re: find files of certain date

Sorry Fuad, that I destruct your topic.
This is the last question(corrective):

I want select the files before dec 20, and do something with them.
Bakos György
Super Advisor

Re: find files of certain date

I have read the answers I think it will work thanks.