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 want to create an alias:

alias readFile='ls file1.todaysdate' where todaysdate is in format 130714.

How would i do this?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

you can use the date command to give you the date in that format:

date +%y%m%d

this gives you the YYMMDD format. In the alias file you can drop that date format into your command with the `` back-ticks like so:

alias readFile='ls file1.`date +%y%m%d`'

everything between the back-ticks is executed and the output is placed instead of the back-ticks. so

echo "hello `whoami`"

would say "hello " followed by your username.

share|improve this answer
    
Another form of the command substitution (backtics) is $(command). The latter variant is better suitable for nesting. –  mpy Jul 16 '13 at 18:53
    
perfect! thanks –  4reel77 Jul 16 '13 at 18:58
    
i tried $(command) and that works as well –  4reel77 Jul 16 '13 at 19:24

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.