Is there a command or tool to undo all commands from a terminal session OR within a specific time-window?

Hello guys,

sorry for asking a non Zorin specific question here, but I find that this community is doing a great job, in terms of communication and giving advice aso.

What happens to me, often times, with Linux, is, that if I face a problem, I will browse the web to find a solution, ending up, copy pasting stuff, I rarely understand - but let's be honest, that's just the way it is - just to find out, stuff is outdated, packages are missing and whatnot.

What frustrates me the most , about this particular situation, is, that I can't help but feel, that this kind of "user-behaviour", comes with a price, which is, slowly but surely, messing up a perfectly fine system. By adding files, I don't know about, altering values, I have no idea about, where they are and what they do and so on.. It's just a super normal thing, every Linux beginner maybe even average user can relate to, that buggs me plenty.

Yes I am aware of apt-get remove and purge yada yada, still, some actions won't be undone with that, plus the terminal, often times, ends up, with so much text, that, even if you try to undo everything by yourself, it turns out to be quite the burdersome situation, which will take quite a bit of time on top of it.

So my question is, as the title says, Is there a command or tool that I can use to (safely) undo all commands I have entered in a terminal tab (session) or that would allow me to choose a timeframe like you can do in modern browsers to delete cache, cookies and so - which would be something like: last hour, last two hours, last 4 hours, today.

Thanks for your replies.

@Edit Tools like Mac OS Time Machine would do the job, I guess. But it has to be setup in a way, that would auto and increment backup your system every 5 minutes or something. I bet there are programs in Linux, that are capable of doing just that. What I am looking for or wondering is, if it wouldn't be more or at least also helpful, to have a command-undro-wrapper command within the terminal, you can quickly apply, when you come to the conslusion "this session was a mess-up" or maybe even as a pop-up feature that would show up, when you close a terminal or terminal-tab, that than would say "click here to undo session" (which will vanish if not pressed within 3 seconds or something) AND would need a second user input "are you sure you wish to undone this terminal session?"

1 Like

Sadly, no. The answer is actually "yes, but it's complicated."
There is no One Command that you can run that can cover all bases like you are asking for.
However, as a person learns their terminal commands, they can learn how to create an applicable command on an as-needed basis for such things.

Let's start small, first, in ways that you can find helpful immediately:

history

That command can show a record of what is stored in ~/.bash_history (or in my case, ~/.zsh_history) listing out all recent commands you have entered.
You can open a terminal and run history, then open a second terminal window and run needed commands to undo certain actions.
Or you can use that to undo recent steps in other ways. For example, if you see you ran a wget command to download a package from a source, you can just open your home directory, locate that package and right click - trash it.

You can Group install and remove actions by separating different package names with a space (i do this a lot, actually...) For example:

sudo apt remove --purge application1 application2 application3 application4 application5 application6 application7 application8 application9 application10 application11 application12 application13 application14 application15

So, viewing your history, note the names of all packages you want to remove, then type out the command as above listing them all in a Text Editor. Then paste that one command into terminal and get rid of them all at once.

You can install the same way:

sudo apt install application1 application2 application3 application4 application5 application6 application7 application8 application9 application10 application11 application12 application13 application14 application15

If you see in your history that you added a repository you do not need, you can Up Arrow to it, then left arrow back to the part where it separates between add-apt-repository and ppa and type in remove, then hit enter to remove that repo.
Example:

sudo add-apt-repository ppa:example/stable

sudo add-apt-repository remove ppa:example/stable

2 Likes

Timeshift, maybe.

1 Like

If you use btrfs you can snapshot you disk before you attempt something and restore if it doesn't work. Or use something like systemback.

2 Likes

WOW ..... never used that command before and according to results of history I have issued 844 commands ..... :astonished:

1 Like

In terminal settings, you can increase the amount of history (or of total lines) displayed.
A person can also open the ~/.bash_history in a text editor and reference it that way.
It's a good idea to move this file over to a fresh install, for the many commands you might enter that you want to easily access, too.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.