Operating System - HP-UX
1758722 Members
3526 Online
108874 Solutions
New Discussion юеВ

list files created yesterday

 
SOLVED
Go to solution
Pando
Regular Advisor

list files created yesterday

Hello All,

I would like to ask how can i list files created yesterday using a single command line.

Thanks.
10 REPLIES 10
Bharat Katkar
Honored Contributor

Re: list files created yesterday

Hi,
Check whether this helps you.
Today is Oct 13 so for yesterday i will do like this.

# ls -al | grep "Oct 12"

Regards,
You need to know a lot to actually know how little you know
Bharat Katkar
Honored Contributor

Re: list files created yesterday

And also for recursive list you need to do

# ls -Ral | grep "Oct 12"

Hope that helps.
Regards,
You need to know a lot to actually know how little you know
Muthukumar_5
Honored Contributor

Re: list files created yesterday

We can do with find command as,


find / -type f -name "*" -exec ls -al {} \; | grep 'Oct 12'

HTH.
Easy to suggest when don't know about the problem!
Pando
Regular Advisor

Re: list files created yesterday

Dear All,

thanks for your quick reply.
Am thinking of putting the date in variable.
Is that possible?
Bharat Katkar
Honored Contributor

Re: list files created yesterday

Hi,
It's possible.

# var1="Oct 12"
# ls -Ral | grep "$var1"

Regards,
You need to know a lot to actually know how little you know
Stefan Schulz
Honored Contributor
Solution

Re: list files created yesterday

Hi Fernando,

if you need a scriptable solution where your "yesterday" is calculated automaticaly try this:

ls -la | grep "$(TZ=$(date +%Z)+24; date '+%b %e')"

I got the datecalculation from some other threads here. It is a common problem to calculate yesterdays date. Check for example this thread:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=541033

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
john korterman
Honored Contributor

Re: list files created yesterday

Hi,

unix does not store any information about the creation time of files. It does, however, store the time of the last change, the time of the last read, and the time of the last change of the inode of the file, but that is all.
You probably have to maintain a database of the creation time yourself - sorry.

regards,
John K.
it would be nice if you always got a second chance
Fred Ruffet
Honored Contributor

Re: list files created yesterday

In a more generic may, you can touch a file to set it a date of midnight, and use find with -newer option

/tmp>touch -t $(date +%m%d)0000 ref_file
/tmp>find . -newer ref_file
.
./pdenq.log
./.oracle
./.oracle/s#7484.1
./export_test.log
./dhcpfifo.root
./dhcpfifo.any
./analyze.20041013.dev_dev.7701.log
./analyze.20041013.test_test.7700.log


Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Hein van den Heuvel
Honored Contributor

Re: list files created yesterday


As observed, there is no creation time recorded as such, you'll have to pick between 'mtime' modification time (the one displayed by ls -l and 'ctime' attribute change time. The 'atime' (ls -ul) is probably not usefull as a simple grep jiggle that.

If 'yesterday' means 'withing the last 24 hours' then it becomes a trivial problem:

find . -mtime -1

Otherwise the suggestion above will help.

Hein.