Hi all,
Can any1 suggest me how can i get the epoch time of file.
i mean...
ls -l test.txt | awk '{print $6,""$7,""$8}' gives me Nov 30 2011...
now is there any way i can convert this into epoch time for this particular file only...
Thanks
ls: Not a recognized flag: -
ls: Not a recognized flag: -
ls: Not a recognized flag: y
ls: Not a recognized flag: =
ls: Not a recognized flag: +
ls: Not a recognized flag: %
GNU not available...
m working in ksh shell
---------- Post updated at 03:23 PM ---------- Previous update was at 03:20 PM ----------
Need to create a script:
where i will pass filename as an argument and have to check if this file shud not be older than 2 days. If file is older than 2 days send mail that file not updated and if its not older than move it to updated folder.
---------- Post updated at 11:42 AM ---------- Previous update was at 11:17 AM ----------
@vipin kumar
If you can't use stat command try this
FILE=test.txt
if [[ ! -f $FILE ]]
then
echo $FILE not exists
else
N=$(find . ! -name . -prune -name $FILE -mtime +2|wc -l)
if [[ $N -eq 0 ]]
then
echo $FILE is updated
else
echo $FILE is older
fi
fi
for existing file this code worked..but when i created new file say vip.txt...thn its showing file not exists instead it shud show that vip.txt is updated bcoz it has been created or modified today not 2 days back..
in short,
if sysdate=27 march 2013
and file date=25 march 2012 or older than that thn it will show not updated else updated.
---------- Post updated at 04:28 PM ---------- Previous update was at 04:27 PM ----------
FILE=mynewfile.txt
touch $FILE
if [[ ! -f $FILE ]]
then
echo $FILE not exists
else
N=$(find . ! -name . -prune -name $FILE -mtime +2|wc -l)
if [[ $N -eq 0 ]]
then
echo $FILE is updated
else
echo $FILE is older
fi
fi
hey, that script worked perfectly fine...plz ignore my previous msg.
Thanks a ton.
Need one more favour.. can u plz explain me that what does this line is doing ,it wud be good if u can explain in detail.
N=$(find . ! -name . -prune -name $FILE -mtime +2|wc -l).
search in the current directory (the first parameter "." ) and not in the subdir (the second block of parameters "! -name . -prune") a file named $FILE ("-name $FILE") older than 2 days (-mtime +2)
The wc -l counts the number of lines returned by the find command - i.e. how many files it found. The script logic uses this value (if it finds zero files, then it was updated less than 2 days ago), so yes, you need it.
EDIT: Normally you could just check the return status of the command, but (iirc) find will only return failure if it can't parse its parameters or it can't locate the path you specified.
great...thanx...
bro..i have one more issue..what if i want to pass file name as command line argument..in that case i shud remove wc -l or is there sm thing else...jus last favour:)