Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

getting date 9 days ago in 10.4

I need to move some files around using the dates that are embedded in the file name, and the unix date command didn't seem to have the -v option back in ancient days of yore. For example, if you run this command in any version of os x from Snow Leopard through Yosemite


ls -l *_`date -v-10d +%m%d`_*.pdf


it finds all of the pdf files with _0510_ in the middle of the file name (or gives a No such file or directory message with the if there aren't any). But when you run it in 10.4, you get:


bash-4.3# ls -l *_`date +%m%d`_*.pdf

ls: *_0520_*.pdf: No such file or directory


bash-4.3# ls -l *_`date -v-10d +%m%d`_*.pdf

date: illegal option -- v

usage: date [-nu] [-r seconds] [+format]

date [[[[[cc]yy]mm]dd]hh]mm[.ss]

ls: *__*.pdf: No such file or directory


Tiger does understand the date +%m%d command, so I can get the files with today's date embedded in them, but try to add the -v option to the date command, and it doesn't work.


So in 10.4 is there any way to get a date in the past/future?

Posted on May 20, 2015 8:26 AM

Reply
Question marked as Best reply

Posted on May 20, 2015 11:30 AM

Hello


Basically you may use this for getting date 10 days ago.



#!/bin/bash # date -j -v-10d '+%m%d' date -r $(( $(date '+%s') - 10 * 86400 )) '+%m%d'




And for ls e.g. -


#!/bin/bash d=$(date -r $(( $(date '+%s') - 10 * 86400 )) '+%m%d') ls *_${d}_*.pdf



Regards,

H

3 replies

May 21, 2015 9:32 AM in response to Mark Jalbert

Mark Jalbert wrote:


Backticks are depreciated use $(...) for command substitution.

Always quote command substitution and variables within a statement.

How is nullglob set on the 10.4 system?

Have you read the date manual on the 10.4 system?


Thanks, guys -- it never occurred to me that it was the backticks that were the problem! Works like a charm now.

getting date 9 days ago in 10.4

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.