Automatic save of .history in .cshrc
- Reply: Sysadmin Lists : "Re: Automatic save of .history in .cshrc"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 20 Feb 2022 13:23:47 UTC
Hi! I set the history to 8000: set history = 8000 set savehist = (8000 merge) I would like to move the first 4000 lines of .history to a directory. Let's call the directory ~/.history_archive. The reason that I don't want to move all the contents of .history, is because I would like to have the recent history for auto completion. I found out a csh script to partly do what I envisioned, from https://forums.freebsd.org/threads/csh-history-file.65582/: set HIST="~/.history" if (`wc --libxo text -l ${HIST} | cut -d '/' -f1` == 2000) then mv ${HIST} ${HIST}.old touch ${HIST} && chmod 600 ${HIST} endif Would the following csh code be correct? Because csh only saves / appends to ~/.history when I log out, I use greater or equal to as the the condition. When there are 6000 lines or more, I split the .history files into two. The first one has 4000 lines, which will be moved to ~/.history_archive, with a file name that contains time information. The other file is moved to be the current ~/.history. set HIST="~/.history" if (`wc --libxo text -l ${HIST} | cut -d '/' -f1` >= 6000) then split -l 4000 ${HIST} mv xaa ~/.history_archive/history-`date +"%Y-%m-%d-%H-%M" ` mv xab ${HIST} chmod 600 ${HIST} endif Cheers, Xianwen