Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

E.g. at the end of the session for each day I want to create a history file with the date attached at the end.

So, say, history > history07162012.txt or something like that.

share|improve this question
1  
I would suggest using a standard timestamp instead of your US specific and unsortable one, i.e. history20120716.txt by using date +%Y%m%d –  jlliagre Jul 17 '12 at 11:53
add comment

1 Answer

up vote 5 down vote accepted

Assuming history files are hidden (beginning with .), I would do like:

ls -1 ~/.*history

With output:

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

Execute:

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

And then:

ls -1 ~/.*history*

With following output:

/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

I hope it can be useful for your question.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.