Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing the date from the 'ls' command 1

Status
Not open for further replies.
Aug 15, 2002
422
US
Hi folks,

Just wanted to see if anyone could tell me how I would go about storing the date (or any column for that matter) in a variable from the 'ls -l' command. It is a requiredment in my script that I check the date & time of each file in the directory. If the file has a date < (now - 5 minutes) mv it...

Thanks in advance for your help...

-pd
 
Yes!!... I got it!!...

# ls -l| awk {'print $6 $7 $8'}

If I could give myself a star I would!!! ;-)

Thanks anyhow...

-pd

 
thread822-355004 may help too ! Dickie Bird
db@dickiebird.freeserve.co.uk
 
Well db... You definately deserve a star for that...

Thanks for the tip!
 
capture the date is easy, compute date-5 mins hard.
suppose the date is: Mar 1 00:01
detracting 5 mins you should get what?
was February 28|29 days ???
i don't believe you can do this in sh.
perl or c offer you the 'stat()' who gives:
last accessed, modified and status-changes dates of files.
see: man stat
(supposed using 'c') you just need to set xxx.st_mtime -= 300;
NOTA: 300 is 60 secs * 5 mins

to capture the datum (supposed sys5 ls) you can enter:

ls -l|sed -e \s/ [ ]*/,/g|cut -d, -f6-9|sed -e 's/,/ /g'
this is readable, sure if you are a sed expert, you just need ONE sed

ls -l|sed -e 's/\(.*\) [ ]*\(.*\) [ ]*\(.*\) [ ]*\(.*\) [ ]*\(.*\) [ ]*\(.*\) [ ]*\(.*\) [

]*\(.*\) [ ]*\(.*\) [ ]*/\6 \7 \8 \9/g'
to get the same output!!! a little confusing :)

NOTA: this is standard regex, you also can applay it to vi,ed,ex,awk,perl... the last 2 have

better shortcuts for: ' [ ]*'

you also can use awk: this is easy to read+type.... you only NEVER get a chance to

unterstand regex!
ls -l|awk '{print $6,$7,$8,$9}'
------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
dickiebird,

I have seen a number of users post a link to a different thread in a message. How do you do that? Can you only do it within a forum, or can you do it inter-forum for threads?

Always learning, Einstein47
(&quot;For every expert, there is an equal and opposite expert.&quot; - Arthur C. Clarke)
 
Hi Einstein47.........
All I do is cut and paste the third line of the title of a thread e.g:-
Home > Forums > Programmers > Languages > UNIX Scripting Forum
Capturing the date from the 'ls' command
thread822-357636

Easy......;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top