Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using terminal on OSX along with the find command to find *.txt files and then rm them with the current time/date stamp. All my files which find locates consists of filename_day_month_year_hour. What I would like to do is to do is replace the filename part and add the current time/date stamp?

share|improve this question
add comment

migrated from stackoverflow.com May 19 '12 at 1:25

This question came from our site for professional and enthusiast programmers.

1 Answer

It's been a while since I've used Bash, but it would be something like this:

for $i in `find /where *.txt` mv $i `date`.txt;
share|improve this answer
    
This will not work. First of all, if find outputs any file with a space in its name, this won't be passed to $i properly. Also, since $(date) expands to Wed Jan 9 10:34:13 CET 2013, for example, the mv wouldn't see the correct argument either—it needs to be quoted. Finally, this isn't even the correct syntax for Bash. After for, there should be a ; do mv …; done. –  slhck Jan 9 '13 at 9:34
    
Cool beans. I said it was a bit since I used bash anyway but I knew it was a one liner. Kudoz –  Jay Jan 9 '13 at 9:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.