如何创建自动附加日期的历史文件?

如何创建自动附加日期的历史文件?

例如,在每天的会话结束时,我想创建一个历史文件,并在末尾附加日期。

所以,比如说,history>history07162012.txt 或类似的东西。

答案1

假设历史文件被隐藏(以 开头.),我想:

ls -1 ~/.*history

带输出:

/home/birei/.bash_history
/home/birei/.mysql_history
/home/birei/.ptksh_history
/home/birei/.sqlite_history
/home/birei/.xsh2_history
/home/birei/.xsh_history

执行:

for hist_file in ~/.*history; do cp "$hist_file" "$hist_file$(date +%m%d%Y).txt"; done

进而:

ls -1 ~/.*history*

具有以下输出:

/home/birei/.bash_history
/home/birei/.bash_history07172012.txt
/home/birei/.mysql_history
/home/birei/.mysql_history07172012.txt
/home/birei/.ptksh_history
/home/birei/.ptksh_history07172012.txt
/home/birei/.sqlite_history
/home/birei/.sqlite_history07172012.txt
/home/birei/.xsh2_history
/home/birei/.xsh2_history07172012.txt
/home/birei/.xsh_history
/home/birei/.xsh_history07172012.txt

我希望它对你的问题有用。

相关内容