How can I recover a corrupted Zsh history file from memory?

Clash Royale CLAN TAG#URR8PPP
For reasons that partially escape me (and are outside the scope of this question), my Zsh history file became corrupt. I have several sessions open that have the history in memory. Is there a way to recover the history file (in its correct format) from what's in memory?
While the output of the history or fc commands looks like this (by default, at least)
57694 type -a ssh-keygen
57695 ssh -v localhost
while the file is in a format like
: 1545938685:133;vim ~/.zshrc
: 1545938820:0;exit
(Obviously these are not the same entries—I just give them to display the format, and therefore the problem I'm facing.)
Is there any way to get fc to display all the data that I would need to recreate the history file as it was before it became corrupted?
(If this is not possible, I can recover most of it from a backup drive, of course, but I would rather recover all of it, and it would be useful to know how to do this in the future.)
zsh command-history
add a comment |
For reasons that partially escape me (and are outside the scope of this question), my Zsh history file became corrupt. I have several sessions open that have the history in memory. Is there a way to recover the history file (in its correct format) from what's in memory?
While the output of the history or fc commands looks like this (by default, at least)
57694 type -a ssh-keygen
57695 ssh -v localhost
while the file is in a format like
: 1545938685:133;vim ~/.zshrc
: 1545938820:0;exit
(Obviously these are not the same entries—I just give them to display the format, and therefore the problem I'm facing.)
Is there any way to get fc to display all the data that I would need to recreate the history file as it was before it became corrupted?
(If this is not possible, I can recover most of it from a backup drive, of course, but I would rather recover all of it, and it would be useful to know how to do this in the future.)
zsh command-history
@jimmij The corrupted file has already been deleted byzsh, so I can't recover by editing the history file.
– iconoclast
Dec 28 '18 at 0:44
@jimmij And since I have57698lines in memory, I'm pretty sure I do have the entire history in memory, based onfc -l 1 | wc -l. What you said maybe true by default, but apparently not with my current Zsh settings.
– iconoclast
Dec 28 '18 at 0:46
OK, so if you are sure have it all thenfc -Wshould write andfc -Aappend history to the file. You can pass filename as an argument.
– jimmij
Dec 28 '18 at 0:59
The only problem (which also occurs withfc -i—or any of the other date options) is that the dates are all wrong before a certain command. I assume that's when the session began, and only commands were loaded into memory, but not dates of previous commands.
– iconoclast
Dec 28 '18 at 1:18
add a comment |
For reasons that partially escape me (and are outside the scope of this question), my Zsh history file became corrupt. I have several sessions open that have the history in memory. Is there a way to recover the history file (in its correct format) from what's in memory?
While the output of the history or fc commands looks like this (by default, at least)
57694 type -a ssh-keygen
57695 ssh -v localhost
while the file is in a format like
: 1545938685:133;vim ~/.zshrc
: 1545938820:0;exit
(Obviously these are not the same entries—I just give them to display the format, and therefore the problem I'm facing.)
Is there any way to get fc to display all the data that I would need to recreate the history file as it was before it became corrupted?
(If this is not possible, I can recover most of it from a backup drive, of course, but I would rather recover all of it, and it would be useful to know how to do this in the future.)
zsh command-history
For reasons that partially escape me (and are outside the scope of this question), my Zsh history file became corrupt. I have several sessions open that have the history in memory. Is there a way to recover the history file (in its correct format) from what's in memory?
While the output of the history or fc commands looks like this (by default, at least)
57694 type -a ssh-keygen
57695 ssh -v localhost
while the file is in a format like
: 1545938685:133;vim ~/.zshrc
: 1545938820:0;exit
(Obviously these are not the same entries—I just give them to display the format, and therefore the problem I'm facing.)
Is there any way to get fc to display all the data that I would need to recreate the history file as it was before it became corrupted?
(If this is not possible, I can recover most of it from a backup drive, of course, but I would rather recover all of it, and it would be useful to know how to do this in the future.)
zsh command-history
zsh command-history
edited Dec 28 '18 at 1:42
Jeff Schaller
39.1k1054125
39.1k1054125
asked Dec 28 '18 at 0:26
iconoclasticonoclast
3,76463768
3,76463768
@jimmij The corrupted file has already been deleted byzsh, so I can't recover by editing the history file.
– iconoclast
Dec 28 '18 at 0:44
@jimmij And since I have57698lines in memory, I'm pretty sure I do have the entire history in memory, based onfc -l 1 | wc -l. What you said maybe true by default, but apparently not with my current Zsh settings.
– iconoclast
Dec 28 '18 at 0:46
OK, so if you are sure have it all thenfc -Wshould write andfc -Aappend history to the file. You can pass filename as an argument.
– jimmij
Dec 28 '18 at 0:59
The only problem (which also occurs withfc -i—or any of the other date options) is that the dates are all wrong before a certain command. I assume that's when the session began, and only commands were loaded into memory, but not dates of previous commands.
– iconoclast
Dec 28 '18 at 1:18
add a comment |
@jimmij The corrupted file has already been deleted byzsh, so I can't recover by editing the history file.
– iconoclast
Dec 28 '18 at 0:44
@jimmij And since I have57698lines in memory, I'm pretty sure I do have the entire history in memory, based onfc -l 1 | wc -l. What you said maybe true by default, but apparently not with my current Zsh settings.
– iconoclast
Dec 28 '18 at 0:46
OK, so if you are sure have it all thenfc -Wshould write andfc -Aappend history to the file. You can pass filename as an argument.
– jimmij
Dec 28 '18 at 0:59
The only problem (which also occurs withfc -i—or any of the other date options) is that the dates are all wrong before a certain command. I assume that's when the session began, and only commands were loaded into memory, but not dates of previous commands.
– iconoclast
Dec 28 '18 at 1:18
@jimmij The corrupted file has already been deleted by
zsh, so I can't recover by editing the history file.– iconoclast
Dec 28 '18 at 0:44
@jimmij The corrupted file has already been deleted by
zsh, so I can't recover by editing the history file.– iconoclast
Dec 28 '18 at 0:44
@jimmij And since I have
57698 lines in memory, I'm pretty sure I do have the entire history in memory, based on fc -l 1 | wc -l. What you said maybe true by default, but apparently not with my current Zsh settings.– iconoclast
Dec 28 '18 at 0:46
@jimmij And since I have
57698 lines in memory, I'm pretty sure I do have the entire history in memory, based on fc -l 1 | wc -l. What you said maybe true by default, but apparently not with my current Zsh settings.– iconoclast
Dec 28 '18 at 0:46
OK, so if you are sure have it all then
fc -W should write and fc -A append history to the file. You can pass filename as an argument.– jimmij
Dec 28 '18 at 0:59
OK, so if you are sure have it all then
fc -W should write and fc -A append history to the file. You can pass filename as an argument.– jimmij
Dec 28 '18 at 0:59
The only problem (which also occurs with
fc -i—or any of the other date options) is that the dates are all wrong before a certain command. I assume that's when the session began, and only commands were loaded into memory, but not dates of previous commands.– iconoclast
Dec 28 '18 at 1:18
The only problem (which also occurs with
fc -i—or any of the other date options) is that the dates are all wrong before a certain command. I assume that's when the session began, and only commands were loaded into memory, but not dates of previous commands.– iconoclast
Dec 28 '18 at 1:18
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491227%2fhow-can-i-recover-a-corrupted-zsh-history-file-from-memory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491227%2fhow-can-i-recover-a-corrupted-zsh-history-file-from-memory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@jimmij The corrupted file has already been deleted by
zsh, so I can't recover by editing the history file.– iconoclast
Dec 28 '18 at 0:44
@jimmij And since I have
57698lines in memory, I'm pretty sure I do have the entire history in memory, based onfc -l 1 | wc -l. What you said maybe true by default, but apparently not with my current Zsh settings.– iconoclast
Dec 28 '18 at 0:46
OK, so if you are sure have it all then
fc -Wshould write andfc -Aappend history to the file. You can pass filename as an argument.– jimmij
Dec 28 '18 at 0:59
The only problem (which also occurs with
fc -i—or any of the other date options) is that the dates are all wrong before a certain command. I assume that's when the session began, and only commands were loaded into memory, but not dates of previous commands.– iconoclast
Dec 28 '18 at 1:18