Alias for viewing logs with todays date

1

I want to create an alias:

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

How would i do this?

4reel77

Posted 2013-07-16T18:34:56.767

Reputation: 13

Answers

3

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.

Mobius

Posted 2013-07-16T18:34:56.767

Reputation: 238

Another form of the command substitution (backtics) is $(command). The latter variant is better suitable for nesting. – mpy – 2013-07-16T18:53:25.227

i tried $(command) and that works as well – 4reel77 – 2013-07-16T19:24:13.833