Append date to filename in linux

后端 未结 5 1428
感情败类
感情败类 2020-12-02 14:38

I want add the date next to a filename (\"somefile.txt\"). For example: somefile_25-11-2009.txt or somefile_25Nov2009.txt or anything to that effect

Maybe a script w

5条回答
  •  日久生厌
    2020-12-02 14:50

    a bit more convoluted solution that fully matches your spec

    echo `expr $FILENAME : '\(.*\)\.[^.]*'`_`date +%d-%m-%y`.`expr $FILENAME : '.*\.\([^.]*\)'`
    

    where first 'expr' extracts file name without extension, second 'expr' extracts extension

提交回复
热议问题