i am now at the point where i do need often some git or docker commands
(like docker system prune -a or docker stop $(docker ps -a -q).

I want to know how do you deal with these partially long commands? is there a way to store and list them, like git config --global --list (but there you see more then the aliases)?
Is the ".zshrc" file the standard way to save commands/aliases? and how can i list them?

Working with aliases is fine, but i don't want to forget the original commands - so that's why i want a list of stored commands.

Now i have the responsible name for that: i want to have a cheat sheet which i can call in my terminal e.g. with $ git-cheat and then a list of my stored git commands appears (like the aliases in git).

Can you please give a few suggestions?

Thanks a lot.

  • Is there any reason that writing these as shell scripts won't work? – Austin Hemmelgarn Aug 23 '17 at 14:27
  • there are no reasons, that something won't work ;) i just ask for suggestions. i am new in shell scripting. can u give me an example? – m1well Aug 23 '17 at 14:33
  • The bare bones basic script consists of a line starting with #!/bin/sh, and one line containing the command you want. From there, just make sure the executable bit is set (chmod +x on the file), and you should be good to go. – Austin Hemmelgarn Aug 23 '17 at 14:37
  • yes i know that i have to start the script with "#!/bin/sh". i ment, if you can get me an example for my question? – m1well Aug 23 '17 at 14:42
  • Ah, sorry, misunderstood, give me a few minutes and I'll have an answer written up that has some examples and also gives you a command to list all of the commands. – Austin Hemmelgarn Aug 23 '17 at 14:46

Here's a reasonably simple solution using shell scripts:

  1. Each command you want to save is put in a 2 line shell script like so:
docker system prune -a
  1. All of these scripts get put in one directory, which you then add to your path if you want them to be trivially accessible.
  2. Assuming they all go in ~/cheat-sheet/, the following script should spit out a list mapping the file name to the command it runs:
commands=`ls ~/cheat-sheet/`
for item in commands ; do
    cmd=`tail -n 1 ~/cheat-sheet/${item}`
    echo "${item}:  ${cmd}"

Note that this requires you to give each of the scripts reasonably descriptive names to be useful, but it's probably one of the quickest possible options without using extra software.

  • thank you, that is great. but i think this is a bit overengineered ;) – m1well Aug 23 '17 at 15:10

if you are interested, i have now implemented a solution and released it on github. (further features are coming today or tomorrow)



I am now at the point where i often use commands like
$ docker system prune -a or $ git reset --soft HEAD^
and i don't want to google them if i need them ad hoc and don't memorize them in this moment.

Aliases are cool, but if i start working only with aliases and someone asks me "how can i reset my commit?" - of course i can't tell him my alias. ;)
The shell history is also cool, but a bit to long (even if you grep).


A tool where i can store all my used shell commands, list them, add new commands and of course also delete commands.

So if i search e.g. for a command to stop all docker container i search in my stored commands:
$ sh script_cheatsheet.sh -l 'docker stop'
and i get an answer of my stored output:
//-------- cheatsheet --------//
list of greped commands:
docker stop $(docker ps -a -q)


You can just run the script and...

...add a command to your cheatsheet:
$ sh script_cheatsheet.sh -a 'git commit --amend'
...show all commands in your cheatsheet:
$ sh script_cheatsheet.sh -l all
...show a specific command in your cheatsheet:
$ sh script_cheatsheet.sh -l 'commit'
...remove a command from your cheatsheet:
$ sh script_cheatsheet.sh -r 'git commit --amend'
...remove all commands from your cheatsheet:
$ sh script_cheatsheet.sh -r all

Furthermore you can...

...check the usage/help:
$ sh script_cheatsheet.sh -h
...check the version:
$ sh script_cheatsheet.sh -v


For a better usage it would be most suitable to create an alias like
alias cheat="sh [path-to-script]/script_cheatsheet.sh"
so that you can run the tool like this:
$ cheat -l all

  • You might add some context with some explanation too. – Pimp Juice IT Aug 24 '17 at 10:06
  • ok i changed it – m1well Aug 24 '17 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.