Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to rename my file to the current timestamp.I know how to get the current timestamp("date +%s") but how can I pipe it to 'mv' command?

share|improve this question
4  
So you can start to sort this out in your head, you should know part of the reason you didn't figure this out was you you were asking the wrong question. What you needed was, "Using the output of one command as arguments for another." Depending on the scenario this can be done with the $() and back-tick operators. This is distinctly different from "piping" data from one program to another. In the case that you had output that you wanted to convert to arguments, you could also use xargs to execute another command with arguments taken from stdin or read to just make a variable out of it. –  Caleb Jun 19 '11 at 19:32

1 Answer 1

up vote 10 down vote accepted

Use something like this (bash):

mv myfile myfile.$(date +%s)

Or alternatively:

mv myfile myfile.`date +%s`

if your shell doesn't do the $(command) thing.

share|improve this answer
    
Thanks.both work for me.I copy and pasted the second because I can't type "`".How do I type this character? –  Nick.h Jun 19 '11 at 17:40
    
Depends on your keyboard... AltGr+7 on a "normal" French AZERTY keyboard. On English layouts it's often on the top-left key (just above tab, on the left of 1). Its ASCII code is 0x60 (96 dec.). –  Mat Jun 19 '11 at 17:45
    
Thanks again for your instant response. –  Nick.h Jun 19 '11 at 17:54
    
One should emphasize that these are backticks around the date command, not ordinary single quotes. –  Andre Holzner Jun 19 '11 at 18:17
2  
I think the importance of back-ticks over single quotes can probably be assumed on a unix site, but it should probably be noted that $() syntax is the newer and preferred format for this operation. –  Caleb Jun 19 '11 at 19:27

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.