How can I rename a file to match the current (rounded) time. If it is for example 10:55 or 11:05 then I would like to rename it to
Something like this:
mv file.txt file_`date +%H`.txt
but with the rounding as described above.
You're trying to round the time to the nearest 3600 seconds.
Generally, to round something, add half a unit, then truncate to that unit; this is easy to do using integer division (divide by the unit and discard the remainder, then multiply by the unit - this will always truncate, i.e. round down, but remember that you already added half a unit).
On Mac OS X (BSD date):
On Linux (GNU date):
Both do the same thing: Print the hour value of the current time + 30 minutes.