1. 0
    What’s your favorite terminal command ? ask programming

So I recently discovered this terminal command on lobste.rs and now it became my favorite git log –graph –decorate –oneline –all

I have been using this command for about a week now and this has been a life saver since it allows you browse git history easily when working on large projects with a lot of commits.

Lastly guys i would like to thank everyone who have enjoyed discussions threads that I started and huge thanks to all those people who replied these threads by sharing their great knowledge with others. Honestly I learned a lot from you guys.

Anyways instead of repetitively posting discussion thread I have decided to post them once a week on Sundays.

I hope everyone had a great weekend and I’m definitely looking forward to great responses from you guys

    1. 7

      Grats on cooling the rate of posting while sticking around! :)

      tig is my favorite replacement for git’s builtins for almost anything related to viewing repository status

      asdf is my preferred language runtime manager, especially when paired with per-project .tool-versions files.

      sl is a fun thing to install on servers to remind people to type carefully

      Honestly, collecting a bunch of little bash scripts to scratch your own itches though is kinda where I’m at these days. I have a cute little snippet for quickly logging notes to myself:

      #! /bin/bash
      set -eou pipefail
      WORK_NOTE_PATH="$HOME/.work_notes"
      printf "\n---\n# $(date -u +"%Y-%m-%dT%H:%M:%SZ")\n\n" >>"$WORK_NOTE_PATH"
      vim + "$WORK_NOTE_PATH"
      

      Easy modification (used elsewhere) is to take the arguments to that script and add them in addition to the date in the notes file.

      Another variant is used to quickly generate dated and slugged notes for meeting minutes.

      1. 4

        Oh wow, I use something similar to your notes script to gather timestamped meeting agenda ideas, but using it to create timestamped meeting minutes is a fantastic idea. (I have ADHD, which comes with something they call time blindness, so timestamps really help me reconstruct how time passed.)

      2. 1

        I have basically this same script, which works great from an open terminal window, but I also have a hammerspoon key binding that works globally that I can type which will:

        • switch to iTerm
        • open a new window with a specific profile I have tweaked for this (it’s partially transparent)
        • run my journal command which does basically the same thing yours does so I’m at the end of the day’s journal file in vim insert mode

        It’s really handy for note taking during video calls and other activities where the terminal window can’t be the primary thing going on.

    2. 5

      Not a command exactly, but I only recently learned about $CDPATH which is great when you’re traversing around large source trees. There are other tools for this, like fzf, but what I love about $CDPATH is it’s deterministic, allowing me to build a muscle memory about commands to move to a desired location. Prior to this I used a lot of aliases that are really just shortcuts to cd with a frequently accessed directory.

    3. 13

      Instead of asking low-effort questions once a week what about writing a blog post what you learned during that week and submitting it here? I’d like that much more…

      1. 4

        Having slept a night I feel like this was rude. I’m sorry, @mraza007.

    4. 3

      I have a shell command that I wrote called mb which I use kind of like mh or mblaze but on my mboxes. It still doesn’t work exactly as I’d like it to, and I’ve had to get into the habit of backing up my mailboxes as I have corrupted them a couple of times, but I find it is becoming my preferred way to interact with mail. Here’s a little show of the interface:

      > mb  32  # "Jeff Kaufman's Writ  04-18 13:00  Web Audio Echo?
      > mb  33  # eBay <ebay@ebay.co.u  04-19 03:08  =?UTF-8?Q?=E2=9C=85_Order_confirm
      > mb  34  # "service@paypal.co.u  04-19 03:09  Receipt for your PayPal payment t
      > mb  35  # Nicolas Petton <nico  04-19 14:18  Emacs 27.0.91 is out!
      > mb  37  # "Nicky Case's Blog:   02-05 01:50  Mr. Sacks
      > mb  38  # "Irreal: jcs" <news@  04-22 18:31  Learning Emacs With Macros
      

      The hash characters mean that I can run the whole line as a command and it’ll pull up the message, without me losing the advantages of having some headers available. In a similar vein, I also have an lm command which I think I found in an article on here quite recently, but I’ve enjoyed using it a lot. It works like apropos, but once again lets me run any line as a command and get the man page straight away:

      $ lm lisp
      man 3 common-lisp-controller   # Common Lisp system management tool
      man 1 lispmtopgm   # convert a Lisp Machine bitmap file into pgm format
      man 1 pgmtolispm   # convert a portable graymap into Lisp Machine format
      man 8 register-common-lisp-source   # internal clc commands
      man 1 sbcl   # Steel Bank Common Lisp
      man 1 zenlisp   # zenlisp interpreter
      
      1. 1

        Have you seen neatmail?

        1. 1

          I hadn’t, but it looks pretty nice, along with a lot of the other software on that page! I’m definitely going to dig into the source, although I won’t use it exactly as is because it doesn’t fit my criterion that I must be able to interact by executing a full line.

          That said, it runs noticeably faster than my mb script which was quickly patched together with Python’s mailbox library. Thanks!

    5. 3

      I had to use double dashes for the command you listed:

      git log --decorate --graph --oneline --all
      

      It’s neat thanks for sharing.

      1. 3

        Tip: a mnemonic is ‘git log A DOG 🐶’:

        • --all
        • --decorate
        • --oneline
        • --graph
        1. 2

          Or you can use an alias. I’ve had the above or one very similar aliased to ‘git lg’.

    6. 2

      endcli

      It closes the Amiga shell. Typing it means you’re done, phew.

    7. 2

      !$ has been my favorite shell “command” lately. It inserts the last argument of the previous command. So, if I blame a file:

      git blame this-file
      

      And then I want to edit that file:

      vim !$
      

      It’s a decent time saver for me.

      1. 7

        Or use Alt-.

        1. 3

          I think I have new favorite.

    8. 2
      #screen emacs
      
    9. 1

      fzf hands down. I never run it directly, but I have it baked into a ~/bin/fuzzy-filter script and many of my shell aliases so it’s a key part of my workflow especially for dealing with situations where you end up with “choose from a list of things with partially memorable names and partial suffixes of uuids or other nonesense”. Like if I want to exec into a running docker container I can drun foo and if there’s only one container who’s name matches foo, the command runs immediately with that container’s name. If there’s more then one match though, fzf pops up a fuzzy filterable list so I type some more to pick the correct container, then the command proceeds with that container name.

    10. 1

      yes might be my favorite just because the source code isn’t a simple loop.

      https://raw.githubusercontent.com/coreutils/coreutils/master/src/yes.c

      pushd/popd are pretty useful to, though I’m not sure shell builtins count as far as “terminal commands” go.

      1. 2

        The AUTOPUSHD option is a feature that I really like in zsh. It effectively turns every cd into a pushd. This way, I don’t have to try to think about or anticipate whether I might later want to pop back to a previous directory.

    11. 1

      I collected a few favorites almost 20 years ago. Looking back at it now, there is one that I still use: color.

      Really, though, asking for a favorite shell command is like asking for a favorite helper function in a programming language. The value of both lies largely in the surrounding context, in the system of names.

    12. 1

      Perhaps not my favourite, but my most popular are:

      $ cut -d';' -f2 ~/.zsh/history | cut -d' ' -f1 | sort | uniq -c | sort -rn | head -n20
        10088 git
         3405 vi
         3217 go
         2922 cd
         2050 l
         1521 fg
         1226 lc
         1042 goatcounter
          910 ls
          894 ag
          764 rm
          568 wm-brightness
          553
          386 cat
          373 psql
          353 reagent
          343 set-screen
          335 man
          318 alsamixer
          299 su
      

      This doesn’t include piped commands (the grep in ls | grep), so it’s not a full list of everything I’ve run. I can’t be bothered to come up with a program to include that too 😅

      My favourites are probably grep and sed, because they’re such useful pieces of plumbing that can fit in so many different situations.

      The most useful custom command I have is probably age, to open ag search results in Vim:

      # "ag edit" and "grep edit".
      age() {
      	vim +'/\v'"$1" +':silent tabdo :1 | normal! n' +':tabfirst' -p $(ag "$@" | cut -d: -f1 | sort -u)
      }
      grepe() {
      	vim +'/\v'"$1" +':silent tabdo :1 | normal! n' +':tabfirst' -p $(grep "$@" | cut -d: -f1 | sort -u)
      }
      

      P.S. informational nitpick: it’s really a shell command, and not terminal command. A terminal just reads input and displays characters, and a command for that is an escape code which moves the cursor or whatnot, whereas the shell interprets the commands you type (while reading the input from the terminal, and sending the output back).

      1. 1

        Your bash one-liner made me curious about what terminal commands I use most often:

            590 yay
            560 g
            488 pass
            442 sudo
            404 cd
            258 rm
            207 nvim
            199 rg
            184 exa
            154 mv
        

        yay is a 3rd party arch linux package manager, g is my alias for git, pass is the standard password manager, rg is the ripgrep utility. Other than those, it’s all pretty commonplace basic command line tools.

    13. 1

      Heya, good to see you’re sticking around.

      To add some interaction to these threads, how about we all try reply to another response, as well as posting our own?

      My favourite shell command … I have a great fondness for the humble tree and tree -if, which see the look-directly-around-you, one-directory-at-a-time ls and gives you a map of the entire directory tree at once. It’s like going to an unfamiliar supermarket and having a bird’s-eye view, instead of having to check every aisle.

      1. 2

        I’d completely forgotten about tree, which is slightly embarrassing as I use it a whole lot. Do you use tree -if with something like pick? I didn’t know about that set of flags but it seems to me that you lose a bit of the usefulness of the visual layout, although that might just be me.

        1. 1

          tree -if prints something like

          /etc/hosts
          /etc/cron/update.sh
          /etc/cron/color-temperature.sh
          /etc/apt/sources.list
          /etc/apt/myconfig
          

          The indentation-based visual layout is nice for small trees. For large trees, where ancestors scroll a long way off the screen, a prefix-based layout shows you the full path directly. Because files in the same part of the tree are next to each other with the same prefix it’s still quite visual.

          1. 3

            Am I missing something, because I don’t see how this differs from find -type f?

            1. 1

              Same output, yes; but I learned about tree long before I learned about find, which is why tree is the one that I’m fond of. Fondness was this post’s prompt, hence.

              Points for mentioning find, though; because it’s always available as part of POSIX, and tree is not.

          2. 1

            Yeah, I tried it after you mentioned it. It might just be me, but I still find that it looks quite like a list of files even with the common parents. It’s cool that you find it helpful though :)

      2. 2

        I would say my favourite command is vim. If you open vim with a path to a folder, rather than a file, it will load the netrw plugin (which is enabled by default) which gives you a directory listing. In that listing, you can move around (with arrow keys or j/k) and you can even search for entries (start typing /git to find .git, for example). You can press - to go up one dir, and t to open something in a new tab. I find that kind of interactive thing to be great for looking around directories!

        1. 2

          You can also vim open a compressed tarball and edit files inside.

    14. 1

      If I had to choose only one, it would be awk, but going through my history file it seems to be ls.

      To replicate @arp242’s command:

      awk -v OFS='\t' '{ c[$1]++ } END { for (i in c) print c[i], i; }' .bash_history  | sort -n
      

      where I get

      ...
      21	vi
      22	sudo
      23	mpv
      24	git
      34	cd
      51	ssh
      75	ls
      

      Other noteworthy commands have to be pandoc and ffmpeg, although ffmpeg is one of those I can barley use (for something a bit more complicated that just simple format conversion) without looking the commands up.

    15. 1

      Absolutely daily I use:

      • l PATTERN [DIR]: list files matching pattern, recursively
      • g PATTERN [DIR]: wrapper around grep with good defaults
      • gg PATTERN: small wrapper around git-grep

      (code is at https://leahneukirchen.org/dotfiles/.zshrc)

    16. -3

      Definitely

      rm -rf /
      

      Give it a try; Edward Snowden approves it as a privacy-tool.

      1. 0

        This should cease this low-effort spam for a while, hopefully.