Infuriatingly that would omit things like unit test runners from the history in case they don't pass. As a developer I tend to re-run failed commands quite often, not sure how widely that applies, though.
It was quite a while before I realised that was possible.
Then not long after starting to use it, that I got fed up and just started opening up the history file and searching in it.
Holy cow!! I didn’t know that.
I have been using history > history.txt to find “that one command for that one thing” I only need once every other month or so. Thanks, now I can just do that.
https://github.com/atuinsh/atuin is a great tool to manage and search your shell history. I especially enjoy it being able to search commands based on the working directory I was in when I ran them.
It also has more features (which I don't use) to manage dotfiles and sync shell history across hosts/devices.
I was going to talk about it too ! Even though I'm on fish (which helps a lot with history search) atuin really changed my habits and made my life easier !
Wow this is really validating for me to read. I’ve been using Linux for a few years but I’m definitely not a computer expert and am intimidated by the command line.
I’ve always felt like googling every command and arrowing up to find an old entry rather than just googling it again marked me as a fake Linux user, not a real one.
Lol don't feel bad, I can do advanced crazy shit with Linux like pivoting the running OS into RAM so I can unmount the boot drive to do whatever without ever rebooting
But I still [Web Search] commands a shit ton of the time LMAO
Ok. Show me the pivot trick. I usually mess with the boot disk through a reboot, but it's been a while (resized the root to clear space for a part) and it was not without anxiety. Interactive work while the host is up is way better.
So you build a chroot in a ramdisk, restart everything active in there and then run the pivot-root that I've seen in the middle of every boot I've ever watched. And that's it?
It's got a back-out in every stage too, maybe. Fantastic. I'll add that to the list for Science Projects I need to do.
Ah. Well. I can not be blameless on this. I also probably use cat unnecessarily still. But less so with grep these days. I'm getting better... I swear!
That's when you start spamming Page Up/Down, Home, End, and / to search within less. Usually seeing various commands jogs my memory, especially when they are grep commands searching for one I use often enough to be useful but infrequently enough to not remember off the top of my head.
yeah I ONLY just recently switched to fish after using zsh and oh my zsh for so long - pretty much since first starting linux cause I once saw someone using it on unixporn and I thought "that's cool"
when I switched to NixOS zsh with all the plugins was a total slog. switched to fish and it just HAS everything that zsh/oh my zsh and the various plugins had but baked in.
so yeah in Fish it's just starting to type something and hoping it's still in the history.
That's super unkind and incorrect. IE was a trash software that was widely available because MS was trying to extend their monopoly into new areas.
Even if it's not your taste, bash is a mature, stable FLOSS package with wide community support. The reason it is so common is due to it's positive attributes, not because there is a plot to make it the only choice available to you.
It's good to know how to do things in bash, since you're going to encounter it pretty often. But, that doesn't mean you shouldn't customize your shell on the machine(s) you use most often. Why stick with the default when there are better options? You're just hobbling yourself.
Fish once again undefeated. If I want to find that weird image magick command I used earlier with foo.png in it I just type foo.png, hit up and its usually the first one. It doesnt matter where foo.png occurs in the command, fish will find it.
With ZSH there's something called "path-completion" that makes that even easier.
Say you want to go to "/usr/local/share/fonts" but that's too much to type out, you can instead type "cd /u/l/s/f" and hit tab. If every path element is unambiguous it will just expand it to "/usr/local/share/fonts". In this case though, "/u/l/" can expand to "/usr/local" or "/usr/lib" so when you hit tab it moves the cursor to just after the "l" to indicate it needs you to distinguish between "/usr/local/" and "/usr/lib". If you just type "o" and hit tab again, it will know that there's only one match for "/usr/lo" and expand that to "/usr/local/" Then there's only one match for "s" which is "share", and only one match for "f" which is "fonts".
That avoids the danger of executing a command with an asterisk wildcard.
Not sure I understand the point of mcfly. zsh and fish have this functionality built in, where pressing Up with a command partially typed will give auto-completions to that partial match.
Yeah. I also use auto-completions for that. McFly does fuzzy finding and because it's a different separate db, for me it works better across many sessions to find commands I had just recently used in another session.
Aliasing cat or any other ubiquitous shell utility to a replacement is a mistake. Garuda did this, and it was driving me crazy why cat was giving me errors. Turns out that they had aliased bat to cat, and since bat is a different program, it didn't work in exactly the same way, and an update had introduced some unexpected behavior.
Drop-in replacements are dumb. Just learn to use a different command.
If you are me, there is no brain space for remembering new commands. I can already barely hold on to few dozens that I use often.
And occasionally when I need "that one that does that niche thing... how was it?" program - I just sit there sifting through logs for couple minutes.
Today it was od (tbh it's od almost half the time; not really the best name to memorize (I really need to make a note or something, so I stop forgetting it, lol))
Also, for this reason I went to great lengths to keep my ~/.zsh_history protected from being randomly deleted/overwritten by mistake, as it happened a couple of times. Currently it's sitting at around 30_000 lines, oldest command is 2 years old.
Did I remember correctly what command sequence I last used that pattern with? Will my data be gone? Will I send a vulgar email to my boss? Who knows, let's find out!
I don't understand people who have the confidence to just blindly run the last matching command like that. Like, are you 100% sure that the last time you ran find was that one, not the one that piped to xargs rm?
At least with zsh you can tab to complete the !find and verify it's what you want before running it. And, AFAIK by default, the shell option hist_verify is set, so if you do just type !find and hit enter, it doesn't run the command, it loads the command into the editing buffer so you can look it over first. Maybe I just have a weak memory, but I really appreciate the footgun prevention. At worst I have to hit enter twice. At best, I save myself a lot of grief.
I've been using
ctrl + Rmore now :3.. though I definitely used to ↑↑↑↑↑↑↑check out fzf (install fzf and add (assuming bash)
eval "$(fzf --bash)"to your .bashrc) Makes ctrl+r a superpowerIt's awesome until you want to put the cursor in a specific spot of a previous command.
But I still use fzf because while I used to do the above, fzf offered more advantage that made switching worth it.
I'll try it if I don't forget it by the next time I have access to my PC lol :3
Ctrl + r with fzf and you’ll never go back.
Woah Ctrl R looks super cool, never knew that I could do that before…
or documentation.
To use ctrl-r I have to remember something about the command. To use up arrow I just have to know about how many commands ago I used it.
Not if you have fzf you don't: https://github.com/junegunn/fzf
Like an interactive fuzzy finding history. It's sick.
So how well you know which command it is of you won't recognize it when you see it..
I knew there was an
In there somewhere
ls .. enter ↑ enter ↑ enter
You may consider using
watch lsI do like that, thanks a lot ulterno!
Now I don't have to type that in again. Phew!
...until you press up one too many times and enter the same command but with a typo. Again.
Been there, done that.
There is an option you can set in .zshrc or .bashrc which only includes lines that exit 0 (success)
Infuriatingly that would omit things like unit test runners from the history in case they don't pass. As a developer I tend to re-run failed commands quite often, not sure how widely that applies, though.
Oh, stuff like
git diffandgit logwill end up being omitted pretty often.And a lot of times, the commands that end with piping into
lessCtrl R
holy fucking shit 🤌💪🤯❤️💯
The number of people who don’t reverse-I-search is too damn high
CTRL+R for those unitiated
reverse-i-search + fzf = <3
It was quite a while before I realised that was possible.
Then not long after starting to use it, that I got fed up and just started opening up the history file and searching in it.
why not
history | grep -iand the search term?even if there are several, you can use ! and the command's line number to run it again
historyis shell dependent.^r
and whenever you forget to sudo:
sudo !!You need this: https://github.com/nvbn/thefuck
Ctrl-r, l ctrl-r, ctrl-r, ctrl-r, ctrl-r, ctrl-r, ctrl-r, ctrl-r, ctrl-r. To get ls.
No way! I didn't know you could cycle through the results like that... awesome!
It’s basically emacs incremental search.
I’ve probably done that for
lstaptaptaptap.... taptaptaptap.... taptaptaptap taptaptaptap taptaptaptap
.... taptaptaptap
... tap ...
... shit I was on a different user when I typed it.
Or "shit, I did in tmux last time so I could close the terminal window."
O(n) access, very efficient.
No, I do not care to share the value of n
Relevant xkcd: https://xkcd.com/1168/
tar -xvf
but only because I had to look it up twice so now my brain has committed it to memory
I don't even know what it does
i just use unar (unarchive) nowadays, since that works with all file formats iirc
Extract a tarball with verbose output from the specified file.
And learn how to use the 'z' option
You don't even need the hyphen!
Mind = blown.
tar --helptar - h
Unfortunately that's not valid.
From man-page:
-h, --dereference follow symlinks; archive and dump the files they point toDamn.
Thanks, we all died.
:)
tar -jcvf archive.tbz ~/stuff/*
Of course I don't know the bomb had bzip2 on it.. I wonder if we can start with ls to see if there's anything to tar or untar
Or, just type the command “history”, find the index number of the desired command, then type “! ”, then .
That's way more mental effort than pressing up a bunch of times.
or Ctrl+R then search? I don't know why some people still bother with
historytbh.Because you can pipe history to grep.
with fzf you get better grep with fuzzy search
This is going to save me so much time pressing the up arrow.
Holy cow!! I didn’t know that. I have been using history > history.txt to find “that one command for that one thing” I only need once every other month or so. Thanks, now I can just do that.
Ctrl-R if you know part of the command.
I typed it once, I'm not typing it again
Substring completion on ZSH. Type in a small part of the command you want to find and then press up.
bash supports this feature too btw
Added to my mental toolbox, thanks!
https://github.com/atuinsh/atuin is a great tool to manage and search your shell history. I especially enjoy it being able to search commands based on the working directory I was in when I ran them.
It also has more features (which I don't use) to manage dotfiles and sync shell history across hosts/devices.
I was going to talk about it too ! Even though I'm on fish (which helps a lot with history search) atuin really changed my habits and made my life easier !
also when they see this post
Wow this is really validating for me to read. I’ve been using Linux for a few years but I’m definitely not a computer expert and am intimidated by the command line.
I’ve always felt like googling every command and arrowing up to find an old entry rather than just googling it again marked me as a fake Linux user, not a real one.
Lol don't feel bad, I can do advanced crazy shit with Linux like pivoting the running OS into RAM so I can unmount the boot drive to do whatever without ever rebooting
But I still [Web Search] commands a shit ton of the time LMAO
Ok. Show me the pivot trick. I usually mess with the boot disk through a reboot, but it's been a while (resized the root to clear space for a part) and it was not without anxiety. Interactive work while the host is up is way better.
Here's an overview https://lemmy.world/comment/11542288 though I never did get around to writing up an actual tutorial lol
So you build a chroot in a ramdisk, restart everything active in there and then run the pivot-root that I've seen in the middle of every boot I've ever watched. And that's it?
It's got a back-out in every stage too, maybe. Fantastic. I'll add that to the list for Science Projects I need to do.
Thanks!
You can use Ctrl-R and Ctrl-Shift-R to search through your history instead of having to push up a bajillion times.
I think that actually makes you a real Linux user...
cat ~/.bash_history | grepUseless use of cat?
You saying I can just skip cat in that command and it works?
history | grep 'cat'My output was empty for that command.
Guess why?
Because
historyonly gives the last few lines in my system.How did I not know this. Thank you!
it's
grep STRING FILEto be preciseor
awk '/STRING/′ FILEif you prefer that for some reasonYes, it was meant to be a self deprecating admission that I have used this unnecessarily verbose command.
Ah. Well. I can not be blameless on this. I also probably use cat unnecessarily still. But less so with grep these days. I'm getting better... I swear!
I always go past it because I go way to fast.
I have more then once gave up on pressing up, hit ctrl + c to reset only to see the command I wanted briefly flash up as I am hitting ctrl + c
$ history | grep 'gre[p]' | less -SDoes fuck all when you can't remember even a piece of the command lol
Then how well you know which command it is when scrolling. At that point it's googleing how do I move a file or whatever your looking for.
That's when you start spamming Page Up/Down, Home, End, and
/to search withinless. Usually seeing various commands jogs my memory, especially when they aregrepcommands searching for one I use often enough to be useful but infrequently enough to not remember off the top of my head.This is the answer
In
fish, you can enter part of the command, and then press up to search for it. It's kinda awesome.yeah I ONLY just recently switched to fish after using zsh and oh my zsh for so long - pretty much since first starting linux cause I once saw someone using it on unixporn and I thought "that's cool"
when I switched to NixOS zsh with all the plugins was a total slog. switched to fish and it just HAS everything that zsh/oh my zsh and the various plugins had but baked in.
so yeah in Fish it's just starting to type something and hoping it's still in the history.
That's what I do in bash except for pressing up it's ctrl+r. FZF does the fuzzy finding for me. It's so convenient.
fish has "directory-aware" autocomplete with inlay hints and a fantastic
historycommand. I do not suffer from such weaknessToo many people still use Bash.
I like zsh on mac because pretty colors
Too many distributions still ship with Bash.
In the real world, the only thing better than perfect is standardized.
Yeah, true. But, it's easy to change.
Bash is the Internet Explorer of shells. It's great for installing a more useful shell.
That's super unkind and incorrect. IE was a trash software that was widely available because MS was trying to extend their monopoly into new areas.
Even if it's not your taste, bash is a mature, stable FLOSS package with wide community support. The reason it is so common is due to it's positive attributes, not because there is a plot to make it the only choice available to you.
Bash might be better than IE. But I think we can agree that it is no longer a good shell.
Its syntax is awful, and lacks many features that other shells have.
It is only so widely used because it is a de facto standard. If bash was created today, barely no one would us it.
That's not true. Internet Explorer was fucking useless for scripting together things, unlike bash.
Internet Explorer shell expansion always trips me up.
What shell do you recommend?
I like zsh, but some people say great things about fish.
My problem with those is bash is always there and just works.
Yes, just like Internet Explorer.
It's good to know how to do things in bash, since you're going to encounter it pretty often. But, that doesn't mean you shouldn't customize your shell on the machine(s) you use most often. Why stick with the default when there are better options? You're just hobbling yourself.
https://marko.tech/journal/fzf-ftw
grep | history [search term]Oops, but yes that's what I meant.
alias hf='history|grep'I do this all the time for that one long command I use monthly like for cert renewals.
You have to be a linux user to use the console now?
history | grep then !cmd no
zsh tab completion also looks through history wich is pretty nice.
Fish once again undefeated. If I want to find that weird image magick command I used earlier with foo.png in it I just type
foo.png, hit up and its usually the first one. It doesnt matter where foo.png occurs in the command, fish will find it....Yeah, you got me.
I accidentally found out one day that I could use a wildcard operator in the terminal instead of a full file or folder name due to always doing this.
Will for example open my "Photo Examples" folder in the working directory or based on the path
With ZSH there's something called "path-completion" that makes that even easier.
Say you want to go to "/usr/local/share/fonts" but that's too much to type out, you can instead type "cd /u/l/s/f" and hit tab. If every path element is unambiguous it will just expand it to "/usr/local/share/fonts". In this case though, "/u/l/" can expand to "/usr/local" or "/usr/lib" so when you hit tab it moves the cursor to just after the "l" to indicate it needs you to distinguish between "/usr/local/" and "/usr/lib". If you just type "o" and hit tab again, it will know that there's only one match for "/usr/lo" and expand that to "/usr/local/" Then there's only one match for "s" which is "share", and only one match for "f" which is "fonts".
That avoids the danger of executing a command with an asterisk wildcard.
works in fish shell as well.
cd /
sudo rm -rf *
Basically the Linux version of deleting system32 but idk I'm not a super Linux nerd yet.
The fun thing is that you can create a file named "-rf *" and hope an admin tried to delete it!
You can use
||between two commands as well. If the first command returns exit code != 0, the second command will run.I.e.
which ansible || pip install ansible.Or && for if you only want the second command to run if the first command succeeded.
This only works until you grow an addiction to making pho at home and start documenting your progress.
I just use mcfly
Not sure I understand the point of mcfly. zsh and fish have this functionality built in, where pressing Up with a command partially typed will give auto-completions to that partial match.
Yeah. I also use auto-completions for that. McFly does fuzzy finding and because it's a different separate db, for me it works better across many sessions to find commands I had just recently used in another session.
I write part of the command then ctrl+r. Using FZF mind you. Such a great utility.
history | fzfalias cat="bat --plain --theme=gruvbox-dark"Aliasing
cator any other ubiquitous shell utility to a replacement is a mistake. Garuda did this, and it was driving me crazy whycatwas giving me errors. Turns out that they had aliasedbattocat, and sincebatis a different program, it didn't work in exactly the same way, and an update had introduced some unexpected behavior.Drop-in replacements are dumb. Just learn to use a different command.
I think it's ok to add this in a personal
.zshrc, not on a distro level:If it breaks something - I'd probably know why and can easily fix it by removing alias/calling cat directly.
Also, scripts almost always use bash or sh in shebang, not zsh. So it only triggers if I type
catin terminal.Also, even zsh scripts don't read your .zshrc by default.
It's better to learn the new command, then it still works when you use a different machine that doesn't have your alias
If you are me, there is no brain space for remembering new commands. I can already barely hold on to few dozens that I use often. And occasionally when I need "that one that does that niche thing... how was it?" program - I just sit there sifting through logs for couple minutes.
Today it was
od(tbh it'sodalmost half the time; not really the best name to memorize (I really need to make a note or something, so I stop forgetting it, lol))Also, for this reason I went to great lengths to keep my
~/.zsh_historyprotected from being randomly deleted/overwritten by mistake, as it happened a couple of times. Currently it's sitting at around 30_000 lines, oldest command is 2 years old.Being able to just enter a partial command, and hit [up] to jump to prior commands that started in the same way in zsh is a godsend.
If you ever have to go back to bash, it supports it as well. In my bashrc:
That's ctrl-p, but I'm sure the up arrow is possible too.
I use vim keybindings and have
ESC,/to do a reverse command search.I'm in this picture, and I didn't like it....
Oh come on! I at least type the beginning so that it filters the history
This is why I like atuin, I can just press up and start typing part of the command and it will likely find it in my history.
You could already do that with just "Ctrl-R" but without atuin redrawing your screen.
The one people see me doing that gets a "huh?" Is:
"Wait! What did you do?" "Oh. Do you not know about bang?"
I love the excitement of using !?
Did I remember correctly what command sequence I last used that pattern with? Will my data be gone? Will I send a vulgar email to my boss? Who knows, let's find out!
That's why you can add ":p" to the end just to print it.
I don't understand people who have the confidence to just blindly run the last matching command like that. Like, are you 100% sure that the last time you ran find was that one, not the one that piped to
xargs rm?At least with zsh you can tab to complete the
!findand verify it's what you want before running it. And, AFAIK by default, the shell optionhist_verifyis set, so if you do just type!findand hit enter, it doesn't run the command, it loads the command into the editing buffer so you can look it over first. Maybe I just have a weak memory, but I really appreciate the footgun prevention. At worst I have to hit enter twice. At best, I save myself a lot of grief.Normally the use case is
It's in my recent memory, but maybe there's been 10 or so commands of me fixing stuff in-between.
I wish this wasn't so painfully true.
Featherpad, copy, paste. Extra work, but you get a work log
Linux Recall