Unix shell script + How to check the file and date

How to check the file is present or not ? If present then check date and if it is current date then give the errore message and exit.
Need unix shell script.
digs developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Which folder ? Recursive (i.e. subfolders also?). If NOT current date, what action?
Brian UtterbackPrinciple Software EngineerCommented:
Define current date? The same as today's date, or less than 24 hours old? Does the file have a specific name or is there more than one or different? Any limitation on which shell (bash, bourne, perl, etc.)
digs developerAuthor Commented:
Suppose there is one file    ABC_08082014.txt  present in one folder.
Folder contains  2 files ... one for current day and other for yesterday.
ABC_07082014.txt   --- yesterday file

So my requirements is check the todays file is present or not.
If todays file is not preasent then create the todays file.
If file is present then give the error message that file is already created.

Need Unix shell script.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

digs developerAuthor Commented:
Please help
Here ya go...

Of course you will have to change new/ to the path of your directory, and this will also just create an empty txt file with todays date.

TD=`date +%d%m%Y`
CHECK=`find new/ -type f -mtime -1 | grep -oh $TD`

if [ "$TD" = "$CHECK" ]; then
	echo "Creating todays file.."
	touch "new/ABC_$TD.txt"

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Assuming the filenames use the date format you showed, then do

TODAY=$(date +%d%m%Y)

cd /to/your/folder

if [ -f ABC_$TODAY.txt ]
      echo "File already exists for today"
     touch ABC_$TODAY.txt

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.