Windows 和 Linux 下生成以当前时间命名的文件

不会shell害死人啊,想按时间生成log文件都能出错。从网上找了很多示例,终于在N多不靠谱的中找到一个靠谱的。

原文如下:

在 Windows、Linux 操作系统,分别利用BAT批处理文件和Shell脚本,生成类似“20110228_082905.txt”以“年月日_时分秒”命名的文件。

Windows BAT批处理文件:
@echo off
set time_hh=%time:~0,2%
if /i %time_hh% LSS 10 (set time_hh=0%time:~1,1%)
set filename=%date:~,4%%date:~5,2%%date:~8,2%_%time_hh%%time:~3,2%%time:~6,2%
echo test >> %filename%.txt


Linux Shell 脚本:
#!/bin/sh
echo test >> $(date -d "today" +"%Y%m%d_%H%M%S").txt

via:http://blog.s135.com/post/459/

( ! ) Warning: Missing argument 1 for cwppos_show_review(), called in /data/www/enjoyphp/wp-content/themes/flat/content-single.php on line 29 and defined in /data/www/enjoyphp/wp-content/plugins/wp-product-review/includes/legacy.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0000354840{main}( ).../index.php:0
20.0000355128require( '/data/www/enjoyphp/wp-blog-header.php' ).../index.php:17
30.110910163032require_once( '/data/www/enjoyphp/wp-includes/template-loader.php' ).../wp-blog-header.php:19
40.111710234176include( '/data/www/enjoyphp/wp-content/themes/flat/single.php' ).../template-loader.php:74
50.161710791120get_template_part( ).../single.php:5
60.161710791640locate_template( ).../general-template.php:167
70.161710791736load_template( ).../template.php:643
80.161710792120require( '/data/www/enjoyphp/wp-content/themes/flat/content-single.php' ).../template.php:686
90.164810776856cwppos_show_review( ).../content-single.php:29

发表评论

电子邮件地址不会被公开。 必填项已用*标注