20

For example, things you do often but not often enough to make a muscle memory? On Linux systems with Bash, I just use bash aliases. If I do it more than once, It gets an alias or a script; cause I won't remember next time. Example of my current desktop aliases :

alias fuck='sudo $(history -p \!\!)'
alias hstat='curl -o /dev/null --silent --head --write-out '\''%{http_code}\n'\'''
alias ls='ls -la --color=auto'
alias pwgen='< /dev/urandom tr -dc "_A-Z-a-z-0-9\#\+=\$" | head -c${1:-15};echo;'
alias rsync='rsync -ah --info=progress2'

And in my bashrc I have the following settings and functions which come in handy when heads down in the terminal:

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
HISTTIMEFORMAT="%Y-%m-%d %T "

####
function stopwatch() {
    local BEGIN=$(date +%s)
    echo Starting Stopwatch...

    while true; do
        local NOW=$(date +%s)
        local DIFF=$(($NOW - $BEGIN))
        local MINS=$(($DIFF / 60))
        local SECS=$(($DIFF % 60))
        local HOURS=$(($DIFF / 3600))
        local DAYS=$(($DIFF / 86400))

        printf "\r%3d Days, %02d:%02d:%02d" $DAYS $HOURS $MINS $SECS
        sleep 0.5
    done
}

function md() {
  pandoc "$1" | lynx -stdin;
}

function weather() {
  ( IFS=+; curl wttr.in/$(curl -s http://ipwho.is/ | jq .postal););
}

So what do you do to remember or recall your most used commands?

all 23 comments
sorted by: hot top controversial new old
[-] datavoid@lemmy.ml 28 points 11 months ago

Up up up up up up up up up up up up up up up up up up up up up

[-] mreiner@beehaw.org 17 points 11 months ago

CTRL+R to search previous commands can help cut down on the number of times you have to scroll up!

[-] Ephera@lemmy.ml 11 points 11 months ago

I'm using Fish, rather than Bash, and it has type-ahead suggestions, which help a lot.

So, I'll type rsync and then it'll show inline that I typed rsync -ah --info=progress2 a long time ago. And then I'll be like, oh wow, this past-me-guy was very smart, I'll be having the same.

Obviously, this is an imperfect system. If you run another rsync command without these flags, it won't directly show these flags next time, because it's not the most recent entry in history.
But it's rare that I know I'll want to run a command again in a few months, so it's still really helpful.
And of course, there is nothing stopping me from creating aliases and scripts as well.

[-] TehPers@beehaw.org 4 points 11 months ago

I use nushell, same thing with the suggestions. With nushell, you can also press up/down to traverse through the command history for commands starting with what you typed. For example, you could type ls and press up a bunch to go through ls | where size > 2kb, ls | where type == 'directory', etc (if you've executed those before).

[-] MangoKangaroo@beehaw.org 4 points 11 months ago

I usually lean on fish autocomplete to remember things for me. Should I write stuff down? Yes. But I'm lazy, so this method is okay. ~~Until I'm on a different machine and end up completely lost.~~

[-] lnxtx@feddit.nl 3 points 11 months ago

fish FTW! Write a fragment of the command used before and press the up key <3

[-] MangoKangaroo@beehaw.org 3 points 11 months ago* (last edited 11 months ago)

I didn't even know about arrowing up for partially-entered commands; I've just been relying on the first autocomplete that pops up. Thanks for that!

[-] furrowsofar@beehaw.org 3 points 11 months ago

I make a bash script for the whole process and document everything in Zim Wiki. I would only make an alias if I want to supply options to an existing command. Just how I do it.

[-] Penguincoder@beehaw.org 1 points 11 months ago

Yeah I have actual notes and processes in my personal wiki too. I don't like having to look up that one command that I only ever rarely use, like the I need to know if this webpage is serving a 200 or not... what did I do last time??

[-] furrowsofar@beehaw.org 1 points 11 months ago

Zim is a desktop Wiki so no serving issues. The other thing I do is just list my script directory or grep it. If I know I have a script I can often find it that way.

[-] Bitrot@lemmy.sdf.org 3 points 11 months ago

I put them in notes in Joplin.

[-] Penguincoder@beehaw.org 3 points 11 months ago

I want to like Joplin and considered using it, but I don't like the electron base it is. And then converting my existing KB to a new format yet again... ugh.

[-] jarfil@beehaw.org 2 points 11 months ago

I've found Joplin to be "acceptable" to share notes from mobile. When sharing through a shared drive, it saves each note as a separate markdown file, so it technically is greppable plain text, my only gripe is it puts all the files in a single dir. I think it can also import them, or you could add notes directly to the dir.

Over time, I've migrated most of my KB to some sort of markdown: Zim Wiki, DokuWiki, Joplin.

I still have some locked up in MediaWiki dumps, probably should spin one up and migrate it all.

[-] jarfil@beehaw.org 3 points 11 months ago

+1 for Zim Wiki. Write down all the process, document with concise high level explanations and keywords, then use the search function.

I also add a settings file to all my bashrc:

https://gist.github.com/jarfil/da3a5a45bf10e1803d18

It's a mix of some aliases from across several distros, some from as far back as 4DOS and a part for Cygwin, a somewhat complex prompt colorizer that highlights remote/local and root/user shells, and some other stuff that's piled up over the years.

[-] GammaGames@beehaw.org 3 points 11 months ago

What does your fuck alias do?

And for my answer: If it’s for a specific tool, I make a helper script. I have one for git and docker

[-] Penguincoder@beehaw.org 7 points 11 months ago

Reruns the last command with sudo (root) cause I fuck up not remembering to sudo quite often.

$ ncdu -rLx /
Warning: error scanning 
some directory sizes may not be correct

$ fuck                                                                                                                                                                                                     
sudo ncdu -rLx /                                                                                         
[sudo] password for 

[-] Contort3860@links.hackliberty.org 5 points 11 months ago

Not the OP and not an expert, but it looks like it redoes the last command with sudo. Would be very useful since I use sudo !! quite often.

[-] GammaGames@beehaw.org 4 points 11 months ago

Oh, nice! I thought sudo !! was short enough πŸ˜†

[-] Contort3860@links.hackliberty.org 3 points 11 months ago

I agree. But I love the fact that it was aliased to fuck. I just use stuff like up for updating or in installing. Haven't gotten creative with them yet.

[-] bedrooms@kbin.social 3 points 11 months ago

Me:

  • write it in a StackOverflow answer
  • or in a markdown notebook
  • keep it in zsh history search

but despite all my attempts of keeping records, whenever I need them,

  • ask ChatGPT
[-] Icarus@beehaw.org 3 points 11 months ago* (last edited 11 months ago)

I don't do much with bash since I primarily do windows admin, but I run into the same issue with powershell.

I have a document in VSCode that I store frequently used commands and any kind of notation/documentation I need to take advantage of it in the future. It's a lot of one or two liners for stuff I know I'm going to forget, like the once a month hyperv cluster update command πŸ˜‚.

Similarly I've added functions to the powershell local and global profiles on my computer/group policy. (contextually similar to bashrc, bash_profile, that load when launching interactive or non interactive shells, as well as user context) That way i can easily execute repeptive commands without having to think!

Basically, I think we all have the same problem and we've forgotten more than we know lol

[-] ercas@beehaw.org 1 points 11 months ago
this post was submitted on 25 Dec 2023
20 points (100.0% liked)

Operating Systems

3768 readers
1 users here now

All things operating system related, from Windows to Mac to Linux distros and the more obscure.

Subcommunity of Technology.


This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

founded 1 year ago
MODERATORS