We all know this. We need to do a specific task and with the help of the internet we find a specific tool alongside command line parameters to do the job right from the shell.
What is a good way of collecting/documenting these snippets on your own for future reference and use? Just a text file in the home folder?
I push them up to my self hosted gitlab server.
i use a joplin notebook. its like a private wiki, and it works on android too.
i usually get to where i’m going using man pages rather than copying wholesale from the web, but when i find something worth saving i usually put the snippet in its own script in
~/.local/bin
, which is in myPATH
. with some modifications to make it generic, of course.I just keep my history file around and have set it up to never truncate. Then
grep
or^R
.I have a folder in my nextcloud, where I save scripts I find and/or use regularly.
commands.txt every command with a one line description and a separator.
just alias them.
Ctrl+R
Just learn the basic POSIX commands (there’s probably 20-25) and understand pipes. Then you can do pretty much anything you’re likely to need from the command line. Sure, there will be more modern flashy friendly tools that come along. Some you’ll integrate into what you do. Some won’t have enough staying power to remember.
No notes. No googling or LLM. Just don’t skip to the end.
spend more time in the shell. you will naturally learn the most commonly used commands and useful flags for them. soon you will be surprised by how much you know. having good typing speed helps reduce the friction a lot. i have not found need to specifically “memorize” anything consciously.
for obscure things, write a script and put it in a scripts folder, have a comment at the top explaining what it does for reference later.
There is a command called
tldr
. it’s works similar to what you have described.If you like TUI you might find this useful:
Thanks, this looks like the tool I was looking for. Being able to store the snippets alongside a description sounds perfect
I do mine in Obsidian, I just have a folder for ‘computer notes’ and whenever I figure out a new thing I drop it in there.
Some stuff I use often I set up as an alias too. So for example I have
alias yt='yt-dlp -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4"'
for my most commonly used yt-dlp settings, so now I can just doyt [URL of video]
to quickly download something from YouTube. Oralias rs="sudo rsync --ignore-existing -rav"
for my rsync settings for a specific backup folder I copy a lot.In my obsidian i use the daily note feature heavily and if i come across a useful snippet or info i will add a tag and content like below. I found tagging to be helpful because i do not have to spend effort up front putting the file in the “right” folder. I have cleaned some of these up by removing them from my daily notes and into dedicated notes, but only after i have collected quite a few for a specific language or tech and there is a need for me to put more structure around the information.
#codesnippet/<language or tech stack> Write a description to help me remember what this is for
<insert code here>
I prefer my
-f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" --concurrent-fragments 12 --throttled-rate 100K -o "%(uploader)s/%(playlist_title|)s/%(playlist_index&{} - |)s%(title)s.%(ext)s"
Since it saves it based on the channel and if is a playlist, it makes a folder based in that
- Channel
-
- Playlist (if is a playlist, otherwise save inside channel)
-
-
- <playlist index> - title.extension (if not a playlist, it doesn’t add the
-
- <playlist index> - title.extension (if not a playlist, it doesn’t add the
-
Not sure if
--concurrent-fragments 12 --throttled-rate 100K
does actually something.I’m interested in the rsync part for backups, do you have a good guide or video for that? Thanks
I’m interested in the rsync part for backups, do you have a good guide or video for that? Thanks
I don’t really have a guide or anything for it to hand, but essentially what that alias is doing is:
rsync
= running rsync--ignore-existing
= as you might have guessed, this tells rsync not to copy a file if it already exists at the destination.-rav
= additional arguments. r = recursive, IE also copy subfolders. a = archive mode, preserves things like symlinks etc. and v = verbose, just tells you extra info about what’s going on.
So with that alias, I can just type
rs [target folder] [destination folder]
and it’ll copy it across exactly as it is, ignore anything that’s already there and tell me precisely what it’s doing.What if I added my own local server in dolphin? Can I use it’s path to sync a local (Linux) folder to the server?
I store it in a few different places depending on usage.
local projects
If I’m in a project or directory context: I’ll echo a useful command to a new
.sh
file. If more than a few build up, I make asnippets
dir there and move them within. Tip: you can quickly run the contents of a snippet without changing permissions by running. <snippet-file.sh>
(“dot space snippet”). You can even pass arguments after.path scripts
For scripts i write to be in the PATH envar (eg
~/.local/bin
if it’s clear, or i add my own in.bashrc
(?)); my scripts accessible any where on my machine: i have a “snippets” dir within that global “my-scripts” dir. These are for things likecase
nested in awhile
loop to pass flags into a script, error checking, or a help-doc snippet. Basically, templates that i often copy into new, global scripts.cli program notes
if i’m making notes about an existing command and a useful combination of flags, i use Obsidian. Each command has it’s own page made from a “CLI” template (auto-populated frontmatter, “useful flags” table, and a dataview query that lists any tags - see below). I have a cli page to automatically list all cli programs made from the cli template via dataview.
compound snippet notes
if i have multiple, different commands piped together that may be useful in the future, took some time to figure out, but are too niche to be a “path script” (see above): I have a “snippets” template and folder in Obsidian, and a snippets page that has a dataview query to list them. These are often promoted “local projects” scripts (above). The snippets themselves are tagged with each command used (
) so that they can be queried and automatically listed on that command’s “cli notes” (above) using dataview.
Might seem complicated (and may well be too much for many people’s needs or style) but the first two are fast storage for immediate, local/contextual usage. The latter two take longer to save but are like a more personalized
tldr
(which is also an integral part of my process).Happy scripting!
If you’re into self hosting, Bytestash is very nice!