Find the answer to your Linux question:
Results 1 to 2 of 2
Hi All, I have a requirement like this, I have to save log files appended with current date and time.I did "logger.sh > log`date +%T%D`" it is saying no such ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2011
    Posts
    2

    Appending date to filenames


    Hi All,
    I have a requirement like this, I have to save log files appended with current date and time.I did "logger.sh > log`date +%T%D`" it is saying no such file or directory.I omitted %D then it works.But I need both.One more thing if I want to put a separator between time and date what to do.For example

    log09:15:20$09/09/11

    Thanks,
    Arka

  2. #2
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,790
    I can see the issue here. The date %D returns / formatted date. e.g. MM/DD/YY

    This will obviously try saving to a file named YY in the folder called "%TMM/DD"

    to get around this, you will likely need to use a different date format.

    As for formatting it, you can literally put whatever formatting you want in the +string.

    e.g. to get what you want, but with - instead of / in the date:

    logger.sh > log-`date +%T$%m-%d-%y`
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •