Adding timestamp to a filename with mv in BASH

前端 未结 6 1751
孤城傲影
孤城傲影 2020-12-07 15:43

Well, I\'m a linux newbie, and I\'m having an issue with a simple bash script.

I\'ve got a program that adds to a log file while it\'s running. Over time that log fi

6条回答
  •  既然无缘
    2020-12-07 16:16

    A single line method within bash works like this.

    [some out put] >$(date "+%Y.%m.%d-%H.%M.%S").ver

    will create a file with a timestamp name with ver extension. A working file listing snap shot to a date stamp file name as follows can show it working.

    find . -type f -exec ls -la {} \; | cut -d ' ' -f 6- >$(date "+%Y.%m.%d-%H.%M.%S").ver

    Of course

    cat somefile.log > $(date "+%Y.%m.%d-%H.%M.%S").ver

    or even simpler

    ls > $(date "+%Y.%m.%d-%H.%M.%S").ver

提交回复
热议问题