Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Can I see your cheatsheet?
346 points by fastily on June 30, 2022 | hide | past | favorite | 169 comments
Almost everyone I know keeps a list of (easily forgettable) command line snippets somewhere. I can't imagine that HN folks would be any different :)

So that said, could I please see your cheatsheet?

I'll go first: https://github.com/fastily/cheatsheet




I use my ebooks for reference:

* GNU grep and ripgrep (https://learnbyexample.github.io/learn_gnugrep_ripgrep/)

* GNU sed (https://learnbyexample.github.io/learn_gnused/)

* GNU awk (https://learnbyexample.github.io/learn_gnuawk/)

* Ruby one-liners cookbook (https://learnbyexample.github.io/learn_ruby_oneliners/)

* Perl one-liners cookbook (https://learnbyexample.github.io/learn_perl_oneliners/)

* Command line text processing with GNU Coreutils (https://learnbyexample.github.io/cli_text_processing_coreuti...)

* Command line text processing with Rust tools (https://learnbyexample.github.io/cli_text_processing_rust/) — work-in-progress

* Computing from the Command Line (https://learnbyexample.github.io/cli-computing/) — work-in-progress


I consider myself pretty experienced at shell-fu and capable of doing most things I set out to achieve in either bash scripts or fearless one-liners. However, my awk is rudimentary at best, I think mostly because it's such an unforgiving environment to experiment in.

These books you've written are great for a bit of first principles insight and then quickly building up to functional usage. I will have no hesitation in referring colleagues to them!

Do you have a patreon or something similar? Do you accept pull requests for collaboration?

Thanks for creating such great free material!


The AWK Programming Language is great too. Every technical book should be written this way: describe feature, show feature through example, include cookbooks of useful commands.

https://ia903404.us.archive.org/0/items/pdfy-MgN0H1joIoDVoIC...


Thanks for the link, had a quick peruse, looks very comprehensive!


Thanks a lot for the feedback :)

Curious about what kind of issues you had with `awk`. Perhaps https://awk.js.org/ could help?

>Do you have a patreon or something similar?

I pay my bills by selling PDF/EPUB versions of these books. Purchase links are mentioned in the 'Buy' page. You can also visit https://learnbyexample.gumroad.com/ or https://leanpub.com/u/learnbyexample

>Do you accept pull requests for collaboration?

Not currently. You can file issues on GitHub (links are mentioned in the preface chapter) for typos/bugs/suggestions/etc.

Markdown source for these books are also available on GitHub.


That AWK REPL in JS is amazing! Just what I need for a playground to refine my understanding of its language. Thank you!

I will consider buying the books and spread the word :) Thanks again!


I suggest:

C-x C-e in the CLI (not sure if it’s zsh only) will open your command line in your $EDITOR - useful to get code highlighting and write multi line commands if that’s the blocker. The problem is iterating.

OR

Pipe your awk input to a file and then use this thing I wrote to build up your awk program. I use it most often with `jq`.

https://github.com/bigH/interactively


I stumbled upon your vi post a few days ago, really like the style. Keep it up!


Thanks a lot for the feedback, feels great to know the content style suited well for you :)


I see you sell your books as ebooks (awesome BTW), but there's no print option. I've been looking into publishing methods for a book I've been writing, and having a print copy is very appealing (I'm a big physical book fan, personally). I see a lot of modern software books are digital only. Is this due to the margins on print being much lower than digital? Print on demand is a really neat concept to me, but seems to come at a cost.

Just curious to hear from someone who's been around the block with this.


I haven't really looked into print on demand. I started with ebooks since that seemed the easiest option for me. And it is easy for readers to get updated versions.

My books are around 100 pages and I've seen a few readers mentioning that they just print it themselves.


Great work! Seriously cool e-books!

(edit: reading this i sound like a jerk. wasn’t trying to be one.) However, these are books not cheat sheets. Cheat sheets are about glance ability and one page ness.


That's a fair point, something like `tldr` and `cheat.sh` mentioned elsewhere in this thread.


Set a huuuuuuuge shell history https://github.com/craigjperry2/dotfiles/blob/aa77ddcbde63bf... then fzf ctrl+r bindings mean you can recall anything right where you need it.

If you’re going to do this then have an escape hatch for commands you don’t want memorised https://github.com/craigjperry2/dotfiles/blob/aa77ddcbde63bf...


protip: use comments to remind yourself or make commands searchable, e.g.

    $ find . -iname 'package.json' -exec jq .version {} \; # get npm module version numbers for all packages
now when you search history you can do so with plain text:

    $ history | grep 'npm module version'
you could of course take this further by 'tagging' commands if you wish and then grep for that tag later to return longer cheatsheets


I‘ve been doing this ever since I migrated from Windows to Mac in 2015. My bash history has over 40k lines, datestamped. I can recall any command I have typed in my terminal in the past seven years. Extremely helpful whenever I need to repeat anything in the terminal.

# Edit

I sometimes add comments to commands via `# This‘ll do this and that` so that I can find the command by those keywords in the bash history.


This. I've been doing this for a couple of years now, I'm really used to it. I've been "traveling" with my history that is over 70k lines. My dot alias file has only 3 aliases (c=clear, q=exit, gti=git).

Hope there's a project out there that helps parse, rank, or do something with a file like this. There must be interesting information.


Is gti=git for capturing typos or some other reason?


It's a typo, but I make it a lot!


Maybe I'm doing something wrong, but my bash history is missing many of my commands. I assumed it was due to poor handling of multiple open terminal windows and tabs.

Is there something you are doing so the different sessions don't clobber each other?


Your file just reminded me I have "broot" installed..

Its sad how I install all those things, forget about them the next day and cd/ls/vi like a caveman.

The problem is much deeper than you think, OP...


Yep, this is my real problem. Install something that looks cool, then get wrapped up in the day-to-day and never make it muscle memory.

Sounds like I should be focusing on "one new workflow thing a week" and make it a daily habit to practice, or something.


To be honest, its not like the current way is slower - its just not that "cool".

I seem to be using "zoxide" (ie "z prj") to jump to one of my projects after opening a terminal, and mostly stay on that folder for a few days.

Some other things I'll do in Finder, etc.


I also use `history | vim -` to search through the history in the context of other things I was attempting to do. Say, if I try some command and it does not work, chances are it's not the first time and I have the correct version on the line bellow :)


a good idea, some notes:

1. 10,000 isn't 'huuuuge' for long lived workstations, but 100k ought to be good for a while (bash, but not zsh, allows disabling truncation entirely with SAVEHIST=-1)

2. if using bash, make sure that this init stuff is sourced by both login and non-login shells (from ~/.bash_profile vs ~/.bashrc respectively)

3. specifying a non-default HISTFILE near your SAVEHIST (as shown in that zshrc link) can go a long way toward avoiding an improperly-configured shell truncating your huge history log, eg point 2


History search is the way, especially with fzf. I love using fzf to pick git branches as well, so long as you use intelligible branch names :)


How do you use fzf for git branches? I didn’t know you could do that.



Exactly like that :)


  - Find all files modified in the last 90 minutes  
    find . -type f -mmin -90  
  - Find all files and do something to each one
    find . -type f -mmin -90 | xargs ls -l  
  - Find all files modified before 2 days ago  
    find . -type f -mtime +2  
  - Removing files older than 7 days  
    find . -type f -mtime +7 -name '*.gz' -exec rm {} \;  
  - Find all files modified after last 2 days  
    find . -type f -mtime -2  
  - Find all files modified at the last 2 day mark  
    find . -type f -mtime 2


With zsh you don't need to use find, fd, or any other external tool.

zsh's built-in globbing features can be used instead.

  - Find all files modified in the last 90 minutes
    print -l **/*(mm-90)
  - Find all files and do something to each one
    print -l **/*(mm-90) | xargs ls -l
  - Find all files modified before 2 days ago
    print -l **/*(m+2)
  - Removing files older than 7 days
    zargs -- **/*(m+7) -- rm
  - Find all files modified after last 2 days
    print -l **/*(m-2)
  - Find all files modified at the last 2 day mark
    print -l **/*(m2)
In most of the above examples "print -l" is used to print the results to the terminal, but you can instead use whatever command you want (as in the "rm" example above).

Many more examples and tips can be seen here: [1]

[1] - http://www.zzapper.co.uk/zshtips.html


The zsh rm command doesn't with too many (say, 100 000) files, execve() fails with: Argument list too long. This works and it is relatively fast (runs rm in big batches): find ... | xargs -d '\n' rm --


Perl is also helpful to pipe to for any tool that outputs lists of files, like

  find . -type f -name '*foo' | perl -ne 'print;chomp;unlink'
And it has the same -0 switch as xargs to pair with find's -print0.

Not helpful in this case since you have other options, but maybe helpful for things like bulk touch, chmod, etc.


You can do the same with:

  zargs -- **/*(m+7) -- rm
I updated my answer above accordingly.


For you can skip xargs for that and just add the -delete argument to find, for readability and profit(!?)


There needs to be a new version of find with a more intuitive UI. (I suspect it exists, but I can't remember the name right now)


This is fd.

    fd --newer 90min
    fd --newer 90min -x ls -l {}
    fd --older 2d
    fd -g '*.txt' --older 7d -x rm {}
    fd --newer 2d
    fd --newer 3d --older 1d


I've been pretty happy with `fd`: https://github.com/sharkdp/fd


Please use `find -print0 | xargs -0` (or -exec) when running commands on files, otherwise xargs will mangle filenames in some cases.


Depending on how you name your files, you want to add -print0 to your find and -o to your xargs. If you have spaces in your file names you want that to carry over in your xargs.

Secondly, you may want to add -n 200 to your xargs so if you have very, very many files bash doesn't complain.

So:

Find all files and do something to each one

    find . -type f -mmin -90 -print0 | xargs -0 -n 1024 ls -l


Find all .txt files containing the word 'foo': find ./ -mount -type f -name "*.txt" -exec grep -iHn 'foo' {} \;

(the -mount stops it traversing into mounted shares)


With zsh:

  grep -iHn 'foo' **/*.txt(.)
Though I'm not sure how to prevent zsh from descending in to other filesystems, as you can with find.


Ooh thanks!!!


http://cht.sh/ - I use this a lot. It outputs a short summary of common commands for many cli tools. You can curl to it https://cht.sh/grep for example or install their cli client


I completely forget that I have this function in my dot files:

doc () { curl "https://cheat.sh/$1" | less }


Cheat Sheet Intro : https://cht.sh/:intro

Cheat Sheet Help : https://cht.sh/:help

Cheat Sheet List of topics : https://cht.sh/:list


This is awesome! Thank you! I am so frequently visiting https://tmuxcheatsheet.com/, and it's not even that great of a cheat sheet.


Glad you found it useful. It has become one of the things I install when I setup a machine.

Being able to use curl as a client as well is so powerful as well. Whenever you are using ssh on some vps you can still get cheatsheets for all your commands.


No maintained cheat sheet here either. I do use `history | grep` quite a lot though.

One thing I try to do is to keep my keyboard shortcuts consistent between programs/systems. That way the chance of my instinct of pressing `<CTRL>+a` to move the cursor to the start of the line will be correct more often.

Another thing I try to do when a project has a set of complex commands that are needed, is to add them as a rule in its Makefile, that way they're available for my colleagues as well.


I use zsh-histdb[1], which records my entire shell history for all time in a database, which also stores:

  • The start and stop times of the command
  • The working directory where the command was run
  • The hostname of the machine
  • A unique per-host session ID, so history from several sessions is not confused
  • The exit status of the command
This the working directory of the command has been especially useful for me to get the context of what I did, not only the command itself.

[1] - https://github.com/larkery/zsh-histdb


I use Ctrl+R chronically for the same thing.


I've been loving mcfly[0], a history search that can be bound to <ctrl+r>. It makes suggestions based on your current directory as well as your command history.

[0] https://github.com/cantino/mcfly


and when history grepping starts to repeat - memorize it


same here - my cheatsheet is `history | grep`


I'm curious why history | grep and not ctrl-R?


Probably because ctrl-R doesn't present you a list in most shells. Maybe you want to scan the list visually and look at neighboring commands. ctrl-R doesn't really take advantage of human vision by showing all results next to each other.


That's pretty much it. I used to have to use quite a few different shells, so `<CTRL> + r` wasn't always available, but `history | grep` usually was. Once I'd got in the the habit of using `history | grep` I found that I liked the extra context provided by seeing a group of commands with a few variations between the lines. So often it helps jog my memory of what parameters I'll need to change before using it.


Agreed on the value of the list. I additionally dedupe as follows:

H() { history | egrep -v '^ *[[:digit:]]+ +H +' | grep "$@" | sort -rk 2 | uniq -f 1 | sort; }


For me that’s it indeed; grep, sometimes with -A -B is much faster in general for me because it might be similar commands which now will appear next to eachother.


Regular expressions. Sometimes you remember two non-adjacent parts. Ctrl-R doesn't let you find "when I used find with awk" unless you type in everything in between.


Ignorance is bliss! Didn't know what ctrl-R does


One of the most useful cheat sheet utilities I've come across is cheat.sh: https://github.com/chubin/cheat.sh

If you don't have it installed it can easily be queried with curl from the command line like: `curl cheat.sh/sed`. The payload is colorized and gives a lot of examples of usage of the command. You can also query "cht.sh" to use fewer characters. There is actually a lot more advanced usage of the tool/service if you check out the README.

Apologies if this isn't what you're looking for.


Wow. All I can say is thank you. This is great.


This surprised me that people do this. I don't have any, since if I have to look up one, it's not really useful :)

But my cheat sheet is google, I usually find what I want in no time.


"my cheat sheet is google"

Useful information disappears from the internet all the time.

If I find something useful I record it myself so I can easily find it again instead of wasting my time searching for something that may no longer exist.


> Useful information disappears from the internet all the time.

If something is really useful it will stick around, maybe some site goes down but there will be others with the same information.


Delete empty files / empty directories

find . -type f -empty -print -delete

find . -type d -empty -print -delete

Move photos/videos to folder, based on their creation date

exiftool -d /home/user/Photos/%Y-%m-%d "-directory<CreateDate" ./VID*.{mp4,jpg}

(or leave the extension out, and all files with EXIF data will be included)


My only real cheatsheet is a list of shortcuts I maintain for programs/apps I use:

    system:
    ctrl+space=switch keyboard input language
    
    iterm2:
    cmd+; = autocomplete
    fn+cmd+< = scroll to top of buffer
    fn+cmd+> = scroll to bottom of buffer
    fn+cmd+^ = pgup buffer
    fn+cmd+v = pgdown buffer
    fn+< = beginning of line
    fn+> = end of line
    shift+cmd+[ = previous tab
    shift+cmd+] = next tab
    cmd+K = delete til end of line
    cmd+enter = full-screen on/off
    cmd+shift+e = show command timeline!!!
    
    chrome:
    opt+cmd+J = devtools
    cmd+] = devtools tab right
    cmd+[ = devtools tab left
    opt+space = start/stop toggl
    fn+cmd+< = move tab left
    fn+cmd+> = move tab right
    fn+cmd+^ = move tab to start
    fn+cmd+v = move tab to end
    
    sublime:
    ctrl+` = open python console
    cmd+shift+P = open command palette
    cmd+P = search open files
    ctrl+opt+C = open in browser with View in Browser package (create tmpfile if dirty)
    cmd+shift+[ = Move to left pane
    cmd+shift+] = Move to right pane
    ctrl+0 = move to sidebar
    cmd+k+b = show/hide sidebar
    cmd+k+u = uppercase
    cmd+k+l = lowercase
    ctrl+shift+v = multiple cursor down
    ctrl+shift+^ = multiple cursor up
    shift+tab = back up tab indentation (at beginning of line)
    cmd+[ = dedent (when highlighted)
    cmd+[ = indent (when highlighted)
    cmd+shift+. = show dotfiles in open file view
    cmd+shit+g (when opening file) = navigate to path for file selection
    
    # edit package override files in /User/user/Library/Application Support/Sublime Text 3/Packages/User/
    
    VS Code:
    option+^ = drag line up
    option+v = drag line down
    ctrl+` = open terminal
    cmd+p, :#<enter> = go to line
    ctrl+enter = open alongside
    cmd+b = open/close side panel
    cmd+option+shift+> = move tab right
    cmd+option+shift+< = move tab left
    cmd+option+F = toggle fullscreen
    cmd+shift+l = highlight all selected
    cmd+shift+o = type fn name to jump to in open file
    cmd+option+shift+c = copy path of active filename
    
    Asana:
    cmd+shift+M: monospace highlighted text



I have this actually, but it typically only lists a small selection of shortcuts for the active application. Also doesn't work for web applications with shortcuts


Mine is a file named oneliners.bash [1], and I have a Bash keybind (Control+I) [2] that runs fzf with that file as input and lets me select a command.

[1]: https://github.com/meribold/dotfiles/blob/e4dc5ee09d9e656346...

[2]: https://github.com/meribold/dotfiles/blob/e4dc5ee09d9e656346...


https://github.com/Toreno96/dotfiles/blob/master/commands.tx...

Beware: I started this long before I became a fan of markdown, so the syntax of the whole file could seem as pretty weird, but it works for me. I mainly do `rg <pattern> ~/commands.txt` in shell or `/<pattern>` in vim when I need to find something in there.

There are also definitely too much commands dumped into the `Etc` section. I should reorganize this some day.


Try using flashcards (Anki) to remember shortcuts if you haven't yet. Just like with learning a foreign language, it's a quick way to get "action -> shortcut" mappings into your brain permanently for recall at any time, rather than relying on a cheatsheet.


If you're not already using Anki, https://www.shortcutfoo.com/ might be the simplest way to go about this.



> mkdir if not exists

  [ -d "${DIR}" ] || (mkdir -p "${DIR}")
No need to check when using "-p".


You are absolutely right :-) I think, that this is a relict, since I personally use an alias for mkdir:

  alias mkdir='mkdir -p'
Thank you


I have a massive Cheatsheet for most languages and many packages- https://github.com/jsfuentes/Code-Cheatsheet

Also hosted on gitbooks: https://openai.gitbook.io/code-cheatsheets/


Very nice. Found your first Mac shortcut immediately helpful.

I'm assuming you commit an Obsidian vault directly. Do you sweep for secrets before you commit? Your layout resembles my own, but I often dump keys / secrets into my vault "temporarily" and forget about removing them later.


Thanks! I built this from the beginning to be public, so have got into the habit to both copy and paste whenever I learn something new and obfuscate secrets.

I have had the current problem of its so massive that finding the specific sheet can take too long. I tried Obsidian, but still look for great fast search



All my CLI: https://kevin.deldycke.com/2006/12/all-my-command-lines/

The one I'm probably the most proud of is that one-liner to produce GIFs:

  $ ffmpeg -i ./source.mp4 -ss 00:24:52.4 -to 00:24:57.0 -filter_complex "[0:v] fps=12,scale=width=480:height=-1:flags=lanczos,subtitles=source.mp4:si=0:force_style='FontName=Arial Black,Bold=-1,FontSize=26',split [a][b];[a] palettegen=64 [p];[b][p] paletteuse" ./meme.gif
Source: https://kevin.deldycke.com/2006/11/video-commands/


For bash, this is my cheatsheet (can be viewed from within bash): https://github.com/darekkay/config-files/blob/master/bash/.c...

I also maintain cheatsheets for some dev stuff: https://github.com/darekkay/config-files/tree/master/cheat-s...

And then there's my Flexbox cheatsheet: https://darekkay.com/flexbox-cheatsheet/


Creating clips from tv recordings:

    ffmpeg -ss 01:59:00.000 -i "interlaced.ts" -ss 00:00:12.000 -t 26 -max_muxing_queue_size 1024 -c:a libopus -b:a 96k -c:v libx264 -crf 20 -vf "yadif=1" -profile:v baseline -level 3.0 -pix_fmt yuv420p -movflags +faststart -y clip.mp4
Make clip compatible with WhatsApp:

    ffmpeg -i in.mp4 -map 0:v:0 -map 0:a:0 -map_metadata -1 -map_chapters -1 -c:v libx264 -preset slow -tune film -crf 32 -c:a aac -b:a 128k -profile:v baseline -level 3.0 -pix_fmt yuv420p -movflags +faststart out.mp4
Copying in various terminals:

    PuTTY: select
    tmux: Shift + select
    cmd: select + Enter in quick edit mode
    Windows Terminal: select + Right Click


Most streaming sites break a video into many small fragments, which are listed in a m4mu file. I have a script to download the fragments one by one using curl. To merge the video fragments back into one file, I do the following.

  Merge video files with ffmpeg
  - Make a file listing all the videos in sequence. E.g.
     file 'video01.ts'
     file 'video02.ts'
     file 'video03.ts'
     ...
  - Generate the file list for files in the current directory.
      (for %i in (*.ts) do @echo file '%i') > filelist.txt
  - ffmpeg command to combine videos
     ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4


For anyone needing this youtube-dl (and ffmpeg if you need post-dl conversion) can do this for you if it's any easier, point it at the index file and let it do its thing


Youtube-dl is great. I just wanted to build it from scratch, and it was very simple once the underlying streaming tech was understood.


I find -vf bwdif much smoother than yadif for action sport replays.


I use twitter https://twitter.com/search?q=from:moreati%20ansible%20tip&sr.... More generally I have a Firefox bookmark set up so "tm search term" searches my previous tweets.

If I ever get round to editting/refining these I plan to do it on https://devhints.io - https://devhints.io/xpath and https://devhints.io/bash are so nice.


My extremely short shell cheatsheet for things I do rarely enough to forget each time:

    Process substitution:
        bash: diff <(echo hello) <(echo world)
        fish: diff (echo hello | psub) (echo world | psub)
    
    Rsync directories:
        rsync -a -v --dry-run other:dir/ dir/
        Syncs the contents of dir (`/` needed)
    
    Script exit handler:
    bash:
        function finish {
          # exit handling code
        }
        trap finish EXIT # EXIT is special and works on normal exit as well as interrupts


Process substitution is one of those tricks that I don't have to look up each time as I find that I'm always using it - but that probably says more about the number of times that I'm given randomly ordered files that I need to compare with diff to figure out what's actually changed.


tab tab tab tab tab tab tab tab As someone who is quite severely dyslexic tab complete changed my life.


As for me, I put together some spaghetti bash functions for taking note while using the terminal (eg run tnote function will let me select one of the last 10 commands, type a description of what it does and move on with my day...i can come back later and sort it out into my notes)...

I then write another small bash script that use consolemd and surge(probably will move to github page at some point) to generate a simple webpage with simple markdown JavaScript library to serve it up along with all the files generated by consolemd so i can use curl in terminal and have it colorfully displayed.

The cheatsheet site is here https://ch.ebfe.pw/.

And you can try it in terminal: curl https://ch.ebfe.pw/intel/splunk

And my code can be found here if you are interested:

https://github.com/santrancisco/cheat


I write down all my commands, ever issued in the terminal, in temporal ordered markdown files per task/project. This means I can go back, compare, see how I did it in the past and improve, if possible. Or investigate, why something isn't working (based on my noted commands, which is eaier in hindsight).


How do you format them? Mine look very verbose, I don't like markdown at all, but since Gitlab/Github renders them, you can't use anything else...


Not sure I understand the question - I use code-blocks (```ls -alh```) or inline code (`ls -alh`). Everything else is comments and descriptions, what I am doing here. I don't really need rendering, most of the time I use Notepad++, or Typora, or my own Gitlab, or the markdown-text app in my nextcloud.


Maybe I do understand: I usually work from Windows, because I prefer the "frontend" over linux. However, all my work I do in WSL. Which allows me having multiple terminals open, multiple Linux OS etc. It is easy to copy&paste code. Perhaps it is not so easy doing everything with plain terminal in linux, e.g. vim, tmux (or, lets say, it requires a longer time to learn doing quick).


Github renders lots of text formats (though not in issues, pull requests), but it's surprisingly hard to find a complete list.

I know that POD (Plain Old Documentation from Perl) and asciidoc are supported, likely many more.


I keep some as shell aliases, shell scripts or Git aliases, but mostly I just use my shell history, finding commands with Ctrl+R and a few characters that I know to be in there somewhere. (If you want to do this, make sure you set its limit high enough so you don’t lose stuff.)


    - List dirs and file count, to find dir with high file count.
      for i in /home/*; do echo $i; find $i | wc -l; done
      for i in /*; do echo $i; find $i | wc -l; done
    - Report space usage of the top level subdirectories.
      du -h --max-depth=2
    - Report space summary only, no directory output.
      du -s -h
    - Find out which device a directory is in.
      df /tmp
      df /home
    - Print of tree of directories
      tree .
    - Disk
      fdisk -l,  list disk partitions
      lsblk,  show a tree of disks, partitions, and lvm volumes
      lsblk -d,  show physical devices
      lsblk -io KNAME,TYPE,SIZE,MODEL,  name/type/size/model


I very often use the while pattern. Where ls -1 and echo $line can be swapped out.

    ls -1 | while read line; do echo $line; done



Like some others, I don't have a list of cheatsheets except my bash history and my browser bookmarks. My bash history atm contains 4575 unique entries (I reset it a few weeks ago). It is like L1 cache to me for accessing most frequently used commands. Beside that I press `*` then Space in browser bar to search my previously bookmarks (I add keywords to them upon bookmarking by modifying the title). Beside these two, nowadays I write Makefiles in every project I work on. That way one can consolidate all commands that otherwise would be forgotten or scattered in configs, in one place.


I use these two commands regularly:

1. `history | grep somecommand` to see a command I used previously. (I have my history set to a bonkers high number.) 2. `curl cht.sh/somecommand` to see a crowdsourced cheatsheet for a command. See: https://cht.sh/grep 3. DuckDuckGo often has good cheat sheets, e.g. https://duckduckgo.com/?q=tmux+cheat

I also use fish, which has nice history-based autocomplete


I use navi: https://github.com/denisidoro/navi

> navi allows you to browse through cheatsheets (that you may write yourself or download from maintainers) and execute commands. Suggested values for arguments are dynamically displayed in a list.

It also lets you use cheatsheets from tldr and cheat.sh from it (besides your own cheatsheets). I've started to mostly just maintain my own, copying what I find most useful from those repositories, though.


For those with larger collections (I'm up to ~350 individual sheets), I'm interested to know you access (find/read/edit) the cheatsheets. My way:

(Mac Desktop): I use xbar [0] with a custom script to create a menubar nested dropdown of all of my cheatsheets. Selecting opens in typora [0] for reading/editing markdown.

(CLI): I use cheat [0] which consumes the same markdown cheatsheet content

    [0]: https://xbarapp.com
    [1]: https://typora.io
    [2]: https://github.com/cheat/cheat


I keep my "lab" diary in txt files for each day and use VSCode.

Would not ever post any of it because these are mostly specific command lines.

Then with VSCode if I need to remind myself of something I search for command I might use and get my whole history with contexts. Then I copy paste/change and keep all that history there.

Never ever I will spend time organizing it into cheat-sheet because it will be waste of time anything that I put into cheat-sheet that I won't use in next 6-12 months will be just cluttering space on such cheat-sheet.


Go examples https://github.com/tomcam/goexamples

The least you need to know about GitHub pages https://tomcam.github.io/least-github-pages/

Soup to nuts psql tutorial https://tomcam.github.io/postgres/


On a related note: has anyone used a good tool for using/inserting these kinds of custom snippets? It would be neat to have a snippet manager with quick search bound to a keypress.



I made my own with search and autocomplete, it works for me and I have it on GitHub, but it's pretty specific to my workflow and there are so many different options in this thread (a lot of which are probably better).

I also liked the idea here to prefix all your scripts https://news.ycombinator.com/item?id=31846902 and would personally recommend using fish or zsh with the improvements from ohmyzsh for autocomplete and hints.


I use https://www.alfredapp.com/help/features/snippets/

Combined with https://www.alfredapp.com/help/features/clipboard/ you get great productivity, especially when working on sys admin terminal kind of stuff


Make sure to create a cheatsheet for how to use your cheatsheet manager.


Honestly I just store them as files (bash scripts if you will), make them executable, chuck ~/scripts into $PATH

Bonus: it's all stored in a git repo

I do kinda live on the command line, ymmv


On Linux, you can make your own very quickly using Rofi and a clipboard manager.


I just maintain one big org-mode file and check it into git.





Usually I'll just search online and read man pages (and experiment different options and solutions) but here's a short list of my most used aliases and functions, I guess that's the closest thing I have to a cheatsheet

  alias private='shopt -uo history'

  alias unprivate='shopt -so history'

  alias gl="git log --all --decorate --oneline --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"

  alias gitlog='git log --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" --abbrev-commit --date=relative --branches'

  alias sha256sum="shasum -a 256"

  alias sha512sum="shasum -a 512"

  alias flushDNSMac="sudo killall -HUP mDNSResponder"

  alias myip="dig +short myip.opendns.com @resolver1.opendns.com"

  alias m1="arch -arm64"

  alias x86="arch -x86_64"

  alias ibrew='arch -x86_64 /usr/local/bin/brew'

  alias upgrade="ibrew upgrade && m1 brew upgrade && mas upgrade"

  alias docker-clean='docker ps -aq | xargs -P $(nproc) -n1 docker rm -f ; docker rmi -f $(docker images --filter "dangling=true" -q --no-trunc)'

  alias autoscalerstatus="kubectl describe -n kube-system configmap cluster-autoscaler-status"

  alias evictedpods="kubectl get pods --all-namespaces --field-selector=status.phase=Failed"

  2qr() {
    qrencode "$1" -t ANSI256 -o -
  }

  curl_status() {
    if [ -n "${1}" ]; then
      curl -L -o /dev/null --silent --head --write-out '%{http_code}\n' "$1"
    fi
  }

  webp_convert() {
    local file="$1"
    cwebp -q 100 "$file" -o "${file%.\*}.webp"
  }

To minify everything (using https://github.com/tdewolff/minify)

  find ./dist/ -type f \( \
    -name "*.html" \
    -o -name '*.js' \
    -o -name '*.css' \
    -o -name '*.svg' \
    -o -name "*.xml" \
    -o -name "*.json" \
    -o -name "*.htm" \
    \) \
    -and ! -name "*.min\*" -print0 |
    xargs -0 -n1 -P4 -I '{}' sh -c 'minify -o "{}" "{}"'


Me and my friends have a funny habit calling these Spellbooks and pretending to be magicians. This leads to all sorts of hilarious interactions.




https://notes.arunsr.in/

cheat sheets, notes, learnings all go here.


Sounds like we need a "github copilot" for the shell. bash on linux can already tell you which command you need to install if necessary. I really don't want to keep cheatsheets any more. I just want to write a shell comment and get the suggestions of the commands. It shouldn't be too hard I think. I guess the problem is how to pay for it.


Here is tool that I use very often: https://github.com/cheat/cheat

Super simple!

Here is example:

> cheat zip

# To create zip file:

zip archive.zip file1 directory/

# To create zip file from directory:

zip -r archive.zip directory/

# To create zip file with password:

zip -P password archive.zip file1

# To join a split zip file (.zip, .z01, .z02, etc):

zip -FF splitZipfile.zip --out joined.zip

# To list, test and extract zip archives, see unzip:

cheat unzip


I have maybe 50 pages of cheat codes worth. I haven't had the time to post them somewhere yet. Remind me... a week from now :D


Remind me... a week from now :D

--> This is actually a real problem on forums --> just to remind a stranger on a forum to commment on something. --> I´m working on a concept / tool to make it simple.

--> Would you like to talk about that? Ron.


  * Some zsh tips
  ** Zero-pad (preserve zeroes) a variable
  Either
  *** typeset -Z2 FOO
  *** printf %02 $FOO
  ** Do arithmetic
  *** examples
  **** addition
  (( count = $count + 1 ))
  ** Loop through a directory of long filenames with spaces
  while read -r line
  do
    echo "'$line'"
  done < <(print -l *(/))
  ** Shell return codes for piped commands
  echo foo | grep bar | tr z a | cat
  echo ${PIPESTATUS[@]}
  
  0 1 0 0
  ** Pass file contents as an argument
  *** foo "$(<bar)"
  *** The above is more idiomatic than:  foo "$(cat bar)"
  ** Sort files numerically
  *** files=(*); command ${(n)files}
  ** Get the last argument passed to a zsh script
  *** $@[-1] or $@[$#]
  *** you could also use $argv if $@ seems too weird
  ** exec an alias
  *** alias exec='exec '
  *** an alias ending in space causes further alias expansion for the next arg
  ** Start zsh without inhereting any environment variables or sourcing zsh init files
  *** env -i zsh -f
  ** Which shell are you in
  *** echo $0
  *** Check ZSH_VERSION:
         if [ -n "${BASH_VERSION+s}" ]; then
             echo 'this is bash'
         elif [ "${ZSH_VERSION+s}" ]; then
             echo 'this is zsh'
         fi
  ** Find files/dirs between certain dates
  *** First:
  zmodload zsh/stat
  autoload age
  *** For files
  **** print -l *(.e#age 2015/01/01 2016/01/01#)
  *** For directories
  **** print -l *(/e#age 2015/01/01 2016/01/01#)
  ** make ^R work in zsh
  bindkey -M viins "^R" history-incremental-search-backward
  ** Search for lots of files
  Will not run in to argument number limits
  
    zargs -- **/bar -- grep foo
  ** Remove leading and trailing spaces in a variable
  First, make sure to "setopt EXENDED_GLOB" in your script!
  
  Then:
  *** Remove leading spaces
  ${FOO## #}
  *** Remove trailing spaces
  ${FOO%% #}
  ** Edit a variable using your EDITOR
  vared FOO
  ** Find files in directory depth of one
  print -l */foo
  ** List all files except for 'foobar'
  print -l *~foobar
  ** List all plain files except for 'foobar'
     print -l *~foobar(.)
  ** List all files starting with 'foo' except for 'foobar'
     print -l foo*~foobar
  ** List all files starting with "tex" but not starting with "text"
     print -l tex*~*text*
  ** List all files which are not symbolic links
  print -l *(^@)
  ** Load zsh modules
  *** zmodload zsh/attr


I actually do most of my tasks in various GUIs. This has a large advantage in discoverability (and for my brain: memorability). So I find no need for cheat sheets in general.

If on command line, I am typically following an installation guide or something so no need for a cheat sheet.

If scripting, I refer to past scripts or use a search engine.



  tldr <command>
is great. It's a cheatsheet for every command and one of the first things I advise newbies to install.


tldr is one of the best things to happen to the command line


I'm probably missing something here, but it seems to me that it's just a summary of the command plus a few examples?

I usually just man the command and / my way either to the Examples section, or search for whatever other question I may have.

But I'm on OpenBSD, where man pages are worth the time you spend reading them.

Other than that, although I always intend to add useful stuff to my ~/txt/scratch, in the end it's either Ctrl-R or history | grep.


Man pages are worth reading. Once you have a good handle on the command TLDR is great. It gives you you just enough to jog your memory.

Searching history or keeping your own notes work but this is easier for me. Everyone finds a work flow they like. It might not be the tool for you.


I keep a long cheatsheet for many-many-many years as a github gist: https://gist.github.com/sorokine/7b032ccb39514e2a64801f63d9e... (yes, it depends upon my dotfiles)


I keep a printed copy of C++ operator precedence around the desk.

https://en.cppreference.com/mwiki/index.php?title=cpp/langua...



My team has a shared knowledge base CLI set up via kb: https://github.com/gnebbia/kb

It’s like a group-maintained collection of cheatsheets. The git sync is buggy but I’ve made it work.


I feel almost embarassed for sharing some of these, but I either remember things the first time I'm exposed to them or am forever doomed to have to look them up.

    ln -s /the/target the_link (can never remember order)

    for f in *.mp4; do mv "$f" "$(echo "$f" | sed s/S1E/S01E/)"; done

    tar -theuniverse (insert xkcd here)

    grep -E 'foo|bar' file (can never remember the flag for regex)


I started remembering the order for ln when I think of it as a copy which just happens to be special. cp SRC DEST is intuitive to me so I just hang ln off that.


I did that as well, also running cp with the -s argument will create a symlink


25 years into this and i still have to look up the ln order. I know for more complex things, but this damn order won't stick in my mind.



My cheatsheet happens to be just my muscle memory. And, for applications I don't use often, mostly just intuitive guesses.

Sounds pretty messy but I've never felt the need to maintain a cheatsheet.

I don't see why one would. I know I'm possibly being naive.


I just use my bach history. I set it to never expire and I back it up, so it has years of commands I can search, either with Ctrl-R or history|grep. Sometimes I put comments in them to help with searching later.

[edit: turns out a lot of people do that!]


I tried to maintain one many years ago, but I could never get in the habit of being consistent about it. So it was short-lived and didn't get much use. I do refer directly to past code all the time, and that serves me fine.


The whole purpose of this section in my website is to have sharable cheat-sheets that I own: https://www.codrut.pro/snippets/


Weirdly, I’ve never thought of keeping a single cheatsheet for command line snippets.

I’ll usually put relevant commands into my project README files but your post has inspired me to start a global cheatsheet of common commands too!



Here is mine Curated Self Study Guide for Computer Science, DevOps, SRE & SysAdmin (https://Learn.SharjeelSayed.COM)


I never did have a cheatsheet. Strange since I've been on the *nix journey since 1998.

I do like the cheat command but it's still not habitual to use it, I grew up with Google so I'm far too dependent on it.


Don't really use a cheat sheet. history and fzf is mostly what i use



POSIX sh parameter expansion cheat sheet:

https://github.com/jwilk/sh-param-expansion


All kept in batch files in a directory with a meaningful name. When I need something what I do a ls <keyword> on the directory and can recon the command I need.


I use my GitHub gists as a cheatsheet: https://gist.github.com/donbrae.




Very similar indeed. Seems the biggest difference is mainly the language the tool was written in.


I'm the author of `cheat`. The two tools are somewhat less similar than they initially appear, due entirely to poor documentation on my part.

If you're interested in a breakdown of the differences, I elaborated on this recently:

https://news.ycombinator.com/item?id=31600605


A friend of mine made this awesome collection: https://devhints.io/


I don't really use a cheatsheet, but I stored all of my snippets in my shell configuration file. In this case, I use fish shell.


my only cheatsheets are customer-specific ... so they're basically unshareable (the general ideas of what's being done apply all over, but there's a lot of environment-specific stuff that I don't want to have to remember all the time :)


less "cheatsheet" and more just general notes for languages and vim and such:

https://github.com/valbaca/notes


I used to keep a list of snippets, but I found a tool that did it better - `tldr` (https://tldr.sh). I can use this tool from the command line instead of going searching my notes for a snippet.

`tldr tar` or whatever.


### Disk and Hardware

Hardware Summary

    sudo lshw -short
    
Get the total disk space left and summary of folder usage

    df -h .; du -sh -- * | sort -hr
    
Simple partition summary

    lsblk

What version of Linux are you running

    uname -a
    > Linux TREEBEARD 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 
      x86_64 x86_64 x86_64 GNU/Linux
    
    lsb_release -a
     > Distributor ID: Ubuntu
     > Description:     Ubuntu 16.04.4 LTS
     > Release:         16.04
     > Codename:     xenial
 
 What flavour of Ubuntu are you running (see https://itsfoss.com/which-ubuntu-install/ )
 
     cat /var/log/installer/media-info
     > Unity
   
How long has the PC been running

     uptime
     >  23:09:26 up 61 days,  8:28,  1 user,  load average: 0.82, 0.48, 0.34

Count files in folder and sub folders

    find . -type f | wc -l

### Files and Folders

Get a tree view of subfolders

    ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
Find the most recently used files including all subdirectories

    find . -type f -mtime -7 -print0 | xargs -0 ls -lt | head
  
Find string in all files (example searchs logs for Exception)

    find /var/log/www.lifepim.com -type f -print0 2>/dev/null | xargs -0 grep --color=AUTO -Hn 'Except' 2>/dev/null
Find a string 'blah' in all files with recursive (deep) search from current folder '.'

    grep -Rnw '.' -e 'blah'
Limit above search to only .html files

    grep -Rn --include=*.html '.' -e 'blah'
    
    
    
### Processes

List all processes

    ps -ef
   
   
Show a tree of processes

    pstree
   
   
Find the processes I am running

    ps -u duncan
    
    
Get list and PID of specific processes (eg python)

    pgrep -a python
    
Show all processes and usage

    top
    htop   (will need to run sudo apt install htop first)
    
### Network

Get IP Address and network details

    /sbin/ifconfig
See list of PC's on the network

    arp -n   
    
    ip -r neigh
    
    nmap -sA 192.168.1.0/24
    
Lookup name of IP Address

    nslookup 162.213.1.246
    > Non-authoritative answer:
    > 246.1.213.162.in-addr.arpa      name = wssa.beyondsecurity.com.
  
Get the IP address of a domain name

     host www.acutesoftware.com.au
    > acutesoftware.com.au has address 129.121.30.188
  
  
 Show the routing table

    route 

Port scanning

    nmap

 
 ### Shell tips
 
 Show top commands from your shell history 
 
     history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
          35 cat
          25 awk
          18 pwd
          15 ls
          14 cd
     
     
  
### Data Collection

Download a file

    wget http://www.acutesoftware.com.au/aikif/AIKIF-Overview.jpg
    
Download a site for offline reading

    wget --recursive  --page-requisites http://www.acutesoftware.com.au/cont_articles.html

### Data extraction

Get a list of URLs from a html file (like an exported list of Chrome bookmarks)

    grep -Eoi '<a [^>]+>' source.html | grep -Eo 'HREF="[^\"]+"' | grep -Eo '(http|https)://[^/"]+' > urls.csv
    
Grep log files

    cat /var/log/www.lifepim.com.access.log  | grep "POST"          # number of posts to lifepim
    cat /var/log/www.lifepim.com.access.log  | grep "login" | wc -l # number of login page accesses
    awk '{print $1}' /var/log/www.lifepim.com.access.log | sort | uniq -c   # count per IP address
    awk '{print $7}' /var/log/www.lifepim.com.access.log | uniq  # list of pages accessed
    
    cat /var/log/www.lifepim.com.error.log | grep "Exception" | uniq      # list of exceptions
    
    awk '{print $11}' /var/log/www.lifepim.com.access.log | sort | uniq -c | grep -v "lifepim"  # count by referrers
    
        1 "https://newsbout.com/id/19184625381"
        1 "https://umumble.com/links/156005/what-software-will-you-trust-when-you-get-senile%3F"
        1 "https://www.producthunt.com/ask/616-what-s-the-best-personal-knowledge-base"
Looping through list of gz files and grepping for blog hit count

        for i in /var/log/www.lifepim.com.access*.gz
        do
            echo -n "Checking zipped logfile $i - "
            zgrep '/blog/' "$i" | wc -l
        done


        Checking zipped logfile /var/log/www.lifepim.com.access.log.2.gz - 45
        Checking zipped logfile /var/log/www.lifepim.com.access.log.3.gz - 112
        Checking zipped logfile /var/log/www.lifepim.com.access.log.4.gz - 92
        Checking zipped logfile /var/log/www.lifepim.com.access.log.5.gz - 62
        Checking zipped logfile /var/log/www.lifepim.com.access.log.6.gz - 64
        Checking zipped logfile /var/log/www.lifepim.com.access.log.7.gz - 85
        Checking zipped logfile /var/log/www.lifepim.com.access.log.8.gz - 213
        Checking zipped logfile /var/log/www.lifepim.com.access.log.9.gz - 80
### Date and Time

Display Annual Calendar for current year

    cal -y 
   
   
Show the current date in ISO format ( yyyy-mm-dd )

    echo $(date -I)
    
Store the current date / time as string in a bash variable

    DATE=`date '+%Y-%m-%d %H:%M:%S'`
    echo $DATE
    
   
### SQL tips

Show table size of selected tables in a schema

    SELECT table_name as 'Database Name', 
    sum( data_length + index_length ) as 'Size in Bytes', 
    round((sum(data_length + index_length) / 1024 / 1024), 4) as 'Size in MB' 
    FROM information_schema.TABLES where table_name like 'as_%' or table_name like 'sys_%' 
    GROUP BY table_name; 
Get a list of column names for a table

    select * from information_schema.columns where table_name = 'as_task';
Show usage in log file grouped by date

    select DATE_FORMAT(log_date, '%Y-%m'), count(*) from sys_log group by DATE_FORMAT(log_date, '%Y-%m') order by 1;
Show usage by user_id and date

    select log_date, user_id, count(*) from sys_log group by log_date, user_id order by log_date;
Show users by week

    select WEEK(log_date), max(log_date) as date_until, count(*) as num_user_actions, 
     count(distinct user_id) as active_users_this_week from sys_log 
     where DATE_FORMAT(log_date, '%Y-%m') > '2018-05-05' group by WEEK(log_date) order by 2;


pwsh


tldr




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: