3

I have a pretty standard directory higherachy, year, month, date, for log files. If I want to go to todays logs I have to type cd logs/2015/12/16/

By itself this wouldn't be bad, but since I actually have dozens of different logs and jump between them often it gets tedious. I want to write a quick alias or script to allow me to quickly jump to today's directory.

I could do this with awk or sed and string manipulation, but I feel like this is over complicating it. is there a simpler tool for doing this then trying to parse and interpret the directories themselves?

Ultimately my final alias/script would likely allow me to do something like "goLog foo" to go to the latest directory of the foo subdirectory of logs, with "goLog bar" doing the same with the bar subdirectory etc.

2

Quickest solution I can think of:

alias goLog="cd log/$(date +%Y/%m/%d)"

Alternatively, a function:

ctd() { cd logs/$(date +%Y/%m/%d) }
1

Quickest solution I can think of:

alias goLog="cd log/$(date +\"%Y\")/$(date +\"%m\")/$(date +\"%d\")"
0

This function should work for you

ctd(){ cd logs/$(date +"%Y")/$(date +"%m")/$(date +"%d") }

Of course you may need to adjust the path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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