Help with touch and timestamps

Hello fellow Unix geeks,
I have been given a very urgent assignment in my office on writing a particular Shell script but I'm very much new to it.I would appreciate any help from you on solving this problem--which might seem very trivial to you.

The Unix flavour is a Sun Solaris one..(not sure).
Basically --the problem is--there are a certain number of files in a certain directory.A script has to be written which will 'touch' all the files within that directory giving those file the current timestamp.However,the trick is that ,the files shouldn't be touched all at once..There has to be a certain gap-say 5 or 7 seconds,between each file.

Please help.

Hello,

Per our forum rules, all threads must have a descriptive subject text. For example, do not post questions with subjects like "Help Me!", "Urgent!!", "Doubt" or anything that does not accurately reflect the nature of your problem. Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".

The reason for this is that nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, the subject field must be something useful and related to the problem!

In addition, current forum users who are kind enough to answer questions should be able to understand the essence of your query at first glance.

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your subject text. You might receive a forum infraction if you don't pay attention to this.

Thank you.

The UNIX and Linux Forums

1 Like
for FILE in dir/*
do
        touch "$FILE"
        sleep 5
done
1 Like

Thanks everyone for your prompt response and advice.
Just a question-it might seem very lame ,but isnce I'm very new to Unix I can be forgiven--

for FILE in dir/* do         
touch "$FILE"       
 sleep 5 done

Here--how do I define File?There are almost 100 shell scripts in a certain directory for which I need to run this script in a loop.
Please help.

 
for FILE in dir/*
do
        touch "$FILE"
        sleep 5
done

You dont need to specify a file.

Just you want to replace the dir/ with your original directory path.

This for loop read all the files inside the directory and execute the touch command for those files.

Thanks a lot itkamaraj.
Another dumb question.How do I run this code?Do I need to create a .sh script and run ./<scriptname.sh> ??
Or do I run it directly?

Regards

yes, you are correct.

before running the script assing the execute permission

 
chmod 755 script.sh