I’ve been homelabbing for a few years now, and recently I’ve really been focusing in on learning how to use gnu/linux. I thought it might be fun to periodically share the things I’ve been learning. The stand outs for me this past week were:

  1. Use the full path when referencing files and directories in bash scripts (Edit: when it makes sense, which is something I’m also still learning. This mkaes sense when the files will always be located in the same place.)
  2. In a bash script, the variable ${file##*/} will get you the name of the file your script is handling (example, when looping over files in a directory. I believe that’s a shell/bash standard variable, but I need to learn where it came from and how it works)
  3. Ubuntu gets a ton of justifiable criticism, but I find Canonical’s Multipass to be a great tool for spinning up Linux virtual machines. Especially on Apple silicon macs.
  4. Piping the output of ls to grep as a variable in a path is a great way to change to a directory you know exists but can’t remember the exact name of. (Example: cd ~/movies/“$(ls ~/movies | grep movie-name)”)
  5. The reason Mac cli utilities have syntax variations compared to the standard gnu/linux utilities is because macOS and its cli utilities are BSD based. This was information I knew at a high level, but had never really understood the implications of until this week.
  6. Related to point 5, if you’re on macOS trying to learn and you’re annoyed by the syntax differences between bsd and gnu utilities, you can run this script from darksonic37 on github to remove the bsd utilities from macOS and replace them with their gnu counterparts. (I have not run or reviewed the script. I found mulitpass first, and so far I’m happy using the Ubuntu virtual machine)
  • genie@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    10 months ago

    Thanks for putting this out for public benefit! I haven’t messed around with MacOS much but the things you’ve mentioned are nice to know.

    I believe that’s a shell/bash standard variable, but I need to learn where it came from and how it works

    You may know this already, but I’ve found the man (as in manual) utility to be one of the most useful things in GNU/Linux user space. I don’t have much insight into ‘${file##*/}’ off the cuff, but I can tell you there’s manual entries for file, sh, and bash that may help you track it down.

    # simply type man [some-command]
    man file
    man sh
    man bash
    man man # very useful for getting started!
    

    Manpages are local to your system so they’re extremely fast to pull up and searchable!

    Here’s some online info on man if you’re interested:

    (30 sec read) Unix stack exchange tips & tricks

    (5 min read) It’s FOSS writeup

    • harsh3466@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      10 months ago

      Yes, thank you! The man pages have been a huge help as I’m working through things. Sometimes I don’t know enough to understand what the man pages are telling me, and then I usually end up on stack exchange looking at a command example that someone has helpfully broken down.

      • genie@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        10 months ago

        It’s definitely a skill that I haven’t mastered either! That being said I think it’s one of the pillars of being a bonafide “super user” and I’d like to set there one day :)

        Maybe I’ll take inspiration from this post and write something up about what I learn in the future about manpages.

        Cheers and happy tinkering!

        • harsh3466@lemmy.worldOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          10 months ago

          I agree, and I’d like to be there as well so that I can easily read and understand a man page.