Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. New post: shell tricks that aren't exactly secret, but aren't always taught either.

New post: shell tricks that aren't exactly secret, but aren't always taught either.

Scheduled Pinned Locked Moved Uncategorized
unixbashshellsysadminfreebsd
12 Posts 11 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • larvitz@burningboard.netL larvitz@burningboard.net

    New post: shell tricks that aren't exactly secret, but aren't always taught either.

    Split into two sections: what works on any POSIX sh (FreeBSD, OpenBSD, Alpine...) and what's Bash/Zsh-specific. Because not everyone is on Linux with bash as their login shell.

    Things like CTRL+W, $_, pushd/popd, fc, set -euo pipefail caveats, and more.

    Link Preview Image
    Shell Tricks That Actually Make Life Easier (And Save Your Sanity)

    Watch someone backspace 40 characters instead of pressing CTRL+W, and you’ll understand why this list exists. A collection of shell tricks-grouped by what wo...

    favicon

    Larvitz Blog (blog.hofstede.it)

    #unix #bash #shell #sysadmin #freebsd #linux #cli

    lutzhuehnken@mastodon.socialL This user is from outside of this forum
    lutzhuehnken@mastodon.socialL This user is from outside of this forum
    lutzhuehnken@mastodon.social
    wrote last edited by
    #3

    @Larvitz I often use "Meta+." (in your config: ALT+. I guess) to get the last argument of the last executed command.

    1 Reply Last reply
    0
    • larvitz@burningboard.netL larvitz@burningboard.net

      New post: shell tricks that aren't exactly secret, but aren't always taught either.

      Split into two sections: what works on any POSIX sh (FreeBSD, OpenBSD, Alpine...) and what's Bash/Zsh-specific. Because not everyone is on Linux with bash as their login shell.

      Things like CTRL+W, $_, pushd/popd, fc, set -euo pipefail caveats, and more.

      Link Preview Image
      Shell Tricks That Actually Make Life Easier (And Save Your Sanity)

      Watch someone backspace 40 characters instead of pressing CTRL+W, and you’ll understand why this list exists. A collection of shell tricks-grouped by what wo...

      favicon

      Larvitz Blog (blog.hofstede.it)

      #unix #bash #shell #sysadmin #freebsd #linux #cli

      joel@gts.tumfatig.netJ This user is from outside of this forum
      joel@gts.tumfatig.netJ This user is from outside of this forum
      joel@gts.tumfatig.net
      wrote last edited by
      #4

      @Larvitz side note, I don’t think OpenBSD has POSIX sh. Quoting the man page

      This version of sh is actually ksh in disguise. As such, it also supports the features described in ksh(1). This manual page describes only the parts relevant to a POSIX compliant sh.

      Just saying as I got caught thinking my scripts were POSIX compliant on OpenBSD and failed when running them using FreeBSD sh 🤦‍♂️

      larvitz@burningboard.netL 1 Reply Last reply
      0
      • joel@gts.tumfatig.netJ joel@gts.tumfatig.net

        @Larvitz side note, I don’t think OpenBSD has POSIX sh. Quoting the man page

        This version of sh is actually ksh in disguise. As such, it also supports the features described in ksh(1). This manual page describes only the parts relevant to a POSIX compliant sh.

        Just saying as I got caught thinking my scripts were POSIX compliant on OpenBSD and failed when running them using FreeBSD sh 🤦‍♂️

        larvitz@burningboard.netL This user is from outside of this forum
        larvitz@burningboard.netL This user is from outside of this forum
        larvitz@burningboard.net
        wrote last edited by
        #5

        @joel thanks for the hint. I actually wasn’t aware of that! Always thought it’s defaulting to a korn shell.

        1 Reply Last reply
        1
        0
        • R relay@relay.mycrowd.ca shared this topic
        • larvitz@burningboard.netL larvitz@burningboard.net

          New post: shell tricks that aren't exactly secret, but aren't always taught either.

          Split into two sections: what works on any POSIX sh (FreeBSD, OpenBSD, Alpine...) and what's Bash/Zsh-specific. Because not everyone is on Linux with bash as their login shell.

          Things like CTRL+W, $_, pushd/popd, fc, set -euo pipefail caveats, and more.

          Link Preview Image
          Shell Tricks That Actually Make Life Easier (And Save Your Sanity)

          Watch someone backspace 40 characters instead of pressing CTRL+W, and you’ll understand why this list exists. A collection of shell tricks-grouped by what wo...

          favicon

          Larvitz Blog (blog.hofstede.it)

          #unix #bash #shell #sysadmin #freebsd #linux #cli

          mcdanlj@social.makerforums.infoM This user is from outside of this forum
          mcdanlj@social.makerforums.infoM This user is from outside of this forum
          mcdanlj@social.makerforums.info
          wrote last edited by
          #6

          @Larvitz I wish I'd known about C-x C-e years ago, and also yesterday it would have been convenient. But now I know it for the future. Thank you!

          1 Reply Last reply
          0
          • larvitz@burningboard.netL larvitz@burningboard.net

            New post: shell tricks that aren't exactly secret, but aren't always taught either.

            Split into two sections: what works on any POSIX sh (FreeBSD, OpenBSD, Alpine...) and what's Bash/Zsh-specific. Because not everyone is on Linux with bash as their login shell.

            Things like CTRL+W, $_, pushd/popd, fc, set -euo pipefail caveats, and more.

            Link Preview Image
            Shell Tricks That Actually Make Life Easier (And Save Your Sanity)

            Watch someone backspace 40 characters instead of pressing CTRL+W, and you’ll understand why this list exists. A collection of shell tricks-grouped by what wo...

            favicon

            Larvitz Blog (blog.hofstede.it)

            #unix #bash #shell #sysadmin #freebsd #linux #cli

            S This user is from outside of this forum
            S This user is from outside of this forum
            sven222@goto.hardwarepunk.de
            wrote last edited by
            #7

            @Larvitz THANK YOU VERY MUCH!!!! A lot of things I did not know up to now. That helps a lot.

            1 Reply Last reply
            0
            • larvitz@burningboard.netL larvitz@burningboard.net

              New post: shell tricks that aren't exactly secret, but aren't always taught either.

              Split into two sections: what works on any POSIX sh (FreeBSD, OpenBSD, Alpine...) and what's Bash/Zsh-specific. Because not everyone is on Linux with bash as their login shell.

              Things like CTRL+W, $_, pushd/popd, fc, set -euo pipefail caveats, and more.

              Link Preview Image
              Shell Tricks That Actually Make Life Easier (And Save Your Sanity)

              Watch someone backspace 40 characters instead of pressing CTRL+W, and you’ll understand why this list exists. A collection of shell tricks-grouped by what wo...

              favicon

              Larvitz Blog (blog.hofstede.it)

              #unix #bash #shell #sysadmin #freebsd #linux #cli

              tux@burningboard.netT This user is from outside of this forum
              tux@burningboard.netT This user is from outside of this forum
              tux@burningboard.net
              wrote last edited by
              #8

              @Larvitz

              Ah, you don’t really need that anymore these days 🫣 — Gemini CLI and Codex are faster anyway 😉

              1 Reply Last reply
              0
              • larvitz@burningboard.netL larvitz@burningboard.net

                New post: shell tricks that aren't exactly secret, but aren't always taught either.

                Split into two sections: what works on any POSIX sh (FreeBSD, OpenBSD, Alpine...) and what's Bash/Zsh-specific. Because not everyone is on Linux with bash as their login shell.

                Things like CTRL+W, $_, pushd/popd, fc, set -euo pipefail caveats, and more.

                Link Preview Image
                Shell Tricks That Actually Make Life Easier (And Save Your Sanity)

                Watch someone backspace 40 characters instead of pressing CTRL+W, and you’ll understand why this list exists. A collection of shell tricks-grouped by what wo...

                favicon

                Larvitz Blog (blog.hofstede.it)

                #unix #bash #shell #sysadmin #freebsd #linux #cli

                fuzzy@oldbytes.spaceF This user is from outside of this forum
                fuzzy@oldbytes.spaceF This user is from outside of this forum
                fuzzy@oldbytes.space
                wrote last edited by
                #9

                @Larvitz Extra bonus fact, this works on anything that uses readline. Python REPL, password prompt, etc. And for even more fun, in your shells, (most shells afaik) you can switch the mode, and use vi style navigation instead of the default emacs style: https://www.gnu.org/software/bash/manual/html_node/Readline-vi-Mode.html

                1 Reply Last reply
                0
                • larvitz@burningboard.netL larvitz@burningboard.net

                  New post: shell tricks that aren't exactly secret, but aren't always taught either.

                  Split into two sections: what works on any POSIX sh (FreeBSD, OpenBSD, Alpine...) and what's Bash/Zsh-specific. Because not everyone is on Linux with bash as their login shell.

                  Things like CTRL+W, $_, pushd/popd, fc, set -euo pipefail caveats, and more.

                  Link Preview Image
                  Shell Tricks That Actually Make Life Easier (And Save Your Sanity)

                  Watch someone backspace 40 characters instead of pressing CTRL+W, and you’ll understand why this list exists. A collection of shell tricks-grouped by what wo...

                  favicon

                  Larvitz Blog (blog.hofstede.it)

                  #unix #bash #shell #sysadmin #freebsd #linux #cli

                  gumnos@mastodon.bsd.cafeG This user is from outside of this forum
                  gumnos@mastodon.bsd.cafeG This user is from outside of this forum
                  gumnos@mastodon.bsd.cafe
                  wrote last edited by
                  #10

                  @Larvitz

                  I find that I tend not to use the `sudo !!` since it's about as easy to type control+p (recall previous command from history), control+a (beginning of the line) and type my "sudo " there which works in most shells (not all support "!!").

                  One other one that I use regularly is control+x,control+e (use my $EDITOR/$VISUAL to edit the command I'm currently typing) and its sibling `fc` (use my $EDITOR/$VISUAL to edit the previous command I just issued). Support varies, but they work in bash & zsh; and OpenBSD's ksh supports `fc` (though it uses ed(1) not your $EDITOR/$VISUAL).

                  1 Reply Last reply
                  0
                  • larvitz@burningboard.netL larvitz@burningboard.net

                    New post: shell tricks that aren't exactly secret, but aren't always taught either.

                    Split into two sections: what works on any POSIX sh (FreeBSD, OpenBSD, Alpine...) and what's Bash/Zsh-specific. Because not everyone is on Linux with bash as their login shell.

                    Things like CTRL+W, $_, pushd/popd, fc, set -euo pipefail caveats, and more.

                    Link Preview Image
                    Shell Tricks That Actually Make Life Easier (And Save Your Sanity)

                    Watch someone backspace 40 characters instead of pressing CTRL+W, and you’ll understand why this list exists. A collection of shell tricks-grouped by what wo...

                    favicon

                    Larvitz Blog (blog.hofstede.it)

                    #unix #bash #shell #sysadmin #freebsd #linux #cli

                    jnareb@fosstodon.orgJ This user is from outside of this forum
                    jnareb@fosstodon.orgJ This user is from outside of this forum
                    jnareb@fosstodon.org
                    wrote last edited by
                    #11

                    @Larvitz About the `pushd` / `popd` trick: you can use it to switch between set of directories with `dirs -v` to get list of directories on stack and `pushd +<n>` (e.g. `pushd +1`) to switch to n-th directory on the stack.

                    About `tee`: I have recently found a nice trick to make the `tee` command useful in presence of progress bars and colors, namely `| tee >(grep -v $'\r' | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' >command.out)` - which probably could be simplified.

                    1 Reply Last reply
                    0
                    • larvitz@burningboard.netL larvitz@burningboard.net

                      New post: shell tricks that aren't exactly secret, but aren't always taught either.

                      Split into two sections: what works on any POSIX sh (FreeBSD, OpenBSD, Alpine...) and what's Bash/Zsh-specific. Because not everyone is on Linux with bash as their login shell.

                      Things like CTRL+W, $_, pushd/popd, fc, set -euo pipefail caveats, and more.

                      Link Preview Image
                      Shell Tricks That Actually Make Life Easier (And Save Your Sanity)

                      Watch someone backspace 40 characters instead of pressing CTRL+W, and you’ll understand why this list exists. A collection of shell tricks-grouped by what wo...

                      favicon

                      Larvitz Blog (blog.hofstede.it)

                      #unix #bash #shell #sysadmin #freebsd #linux #cli

                      I This user is from outside of this forum
                      I This user is from outside of this forum
                      i5513@burningboard.net
                      wrote last edited by i5513@burningboard.net
                      #12

                      @Larvitz You must tell in your article about Alt-[0-9] (really Alt-n where n is a number) feature when you talk about ALT-F, ALT-B and ALT-. , CTRL-W and maybe more ...

                      It allow you to modify the target. Move n words before / after o select the n th argument, removing n words ...

                      Great post!!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups