Essential Linux Commands - uname, hostname, basename, dirname & logname

Sdílet
Vložit
  • čas přidán 26. 08. 2024
  • In this video, I discuss five incredibly useful command line utilities: uname, hostname, basename, dirname and logname. All of these programs are part of the GNU core utilities that are installed on every GNU/Linux distribution. You will find these utilities useful, not only as command line programs, but also in scripting.
    REFERENCED:
    ► linux.die.net/...
    ► linux.die.net/...
    ► linux.die.net/...
    ► linux.die.net/...
    ► linux.die.net/...
    WANT TO SUPPORT THE CHANNEL?
    💰 Patreon: / distrotube
    💳 Paypal: www.youtube.co...
    🛍️ Amazon: amzn.to/2RotFFi
    👕 Teespring: teespring.com/...
    DONATE CRYPTO:
    💰 Bitcoin: 1Mp6ebz5bNcjNFW7XWHVht36SkiLoxPKoX
    🐶 Dogecoin: D5fpRD1JRoBFPDXSBocRTp8W9uKzfwLFAu
    📕 LBC: bMfA2c3zmcLxPCpyPcrykLvMhZ7A5mQuhJ
    DT ON THE WEB:
    🕸️ Website: distrotube.com/
    📁 GitLab: gitlab.com/dwt1
    🗨️ Mastodon: fosstodon.org/...
    👫 Reddit: / distrotube
    📽️ LBRY/Odysee: odysee.com/@Di...
    FREE AND OPEN SOURCE SOFTWARE THAT I USE:
    🌐 Brave Browser - brave.com/dis872
    📽️ Open Broadcaster Software: obsproject.com/
    🎬 Kdenlive: kdenlive.org
    🎨 GIMP: www.gimp.org/
    💻 VirtualBox: www.virtualbox...
    🗒️ Doom Emacs: github.com/hli...
    Your support is very much appreciated. Thanks, guys!

Komentáře • 46

  • @scheimong
    @scheimong Před 2 lety +16

    A somewhat common use of `dirname` is if you want to write to a file (e.g. a log) in the same directory as your script. You can't simply do `echo text >log` because the user of the script may be calling it from a different working directory.
    So what you would do is first call `cd $(dirname $0)` to set your working directory to where your script is, then write to your file.

    • @bobrieber535
      @bobrieber535 Před 2 lety

      you can also:
      #!/bin/node
      let elems = process.argv.split("/");
      elems.pop();
      console.log(elems.join("/"));

  • @vince6792
    @vince6792 Před 2 lety +2

    Great info! No one should be afraid of the terminal or think they need to remember every command. I've been on Arch for years and I still find looking up a command or script necessary.

    • @Finkelfunk
      @Finkelfunk Před 2 lety +1

      The only thing you need to remember is how you have to look up stuff you don't remember. The man pages exist for a reason too, no one can remember 15 flags for 60 different commands you most likely have to use less than once a year.

    • @vince6792
      @vince6792 Před 2 lety

      @@Finkelfunk your explanation explains it exactly

  • @Finkelfunk
    @Finkelfunk Před 2 lety +4

    Literally every Arch user once they are done setting up Arch: _installs neofetch to show off_
    uname: "Am I a joke to you?"

  • @wyattarich
    @wyattarich Před 2 lety +2

    You skipped a beat here DT, you should have used the SystemD way of hostnamectl! It also feels appropriate to mention base/dirname is never really used outside of shell scripting. Logname is also a good opportunity to introduce people to the `who` command for viewing logged in users. Great video as always.

  • @it_spec_notes
    @it_spec_notes Před 2 lety +2

    You are the best Linux teacher on CZcams! Thank you for the video! I started using Emacs after your videos. I love it when you talk more and more about new packages in Emacs and new useful programs for Linux. I hope you continue posting your videos on CZcams. From Russia with love ❤

    • @der_Grosse
      @der_Grosse Před 2 lety

      4uck you ruZZia from Ukraine! Слава Україні! Смерть російським ворогам!!!

  • @n0kodoko143
    @n0kodoko143 Před 2 lety +1

    Thanks Derek! Thanks patrons!

  • @guilherme5094
    @guilherme5094 Před 2 lety +1

    👍 DT!

  • @paulg3336
    @paulg3336 Před 2 lety +9

    Well, the first sentence in this video is guaranteed to send windows users running screaming ,back to their favourite spyware

    • @gadflyofhumanity_6847
      @gadflyofhumanity_6847 Před 2 lety +4

      Good, f-em we need to keep desktop Linux a niche, NOT make it mainstream! When things go mainstream they get ruined by the normies.

    • @gimcrack555
      @gimcrack555 Před 2 lety +1

      @@gadflyofhumanity_6847 I thinks that's why Linux never fought hard to make to the mainstream. I like how you put it; The normies would just ruin it for the rest of us geek people.

    • @astroid-ws4py
      @astroid-ws4py Před 2 lety

      @@gadflyofhumanity_6847 Linux will never be a normy thing due to the terminal and due to the availability of so many options to tweak the system and due to Linux being built around the concept of open source software code availability and the ability to compile and run it directly from the terminal. And it is a good thing. But we as Nerds should make the transition to Linux for “would be Nerds” and “potentially Nerds” as clean and seamless as possible and thankfully due to the many great channels about Linux that info becomes available to anyone who wants to start this adventure...

  • @sukhchainsingh398
    @sukhchainsingh398 Před 2 lety +1

    Hey DT, Which Desktop Environment would you prefer using if tiling window managers weren't an option ?
    Please tell us reason for your choice too.
    Love your videos by the way 👍

  • @sussusamogus7831
    @sussusamogus7831 Před 2 lety

    Great guide DT, thank you for this :)

  • @richardharding760
    @richardharding760 Před 2 lety

    Hey dt hi from England,your content is great, have you written any books on Linux?

  • @michaelnapitupulu9269
    @michaelnapitupulu9269 Před 2 lety

    Thanks, dt :)

  • @JHACbiz
    @JHACbiz Před 2 lety

    DT: have you ever done a video on Avahi. I'm particularly interesting in messing with Zget but not sure how to create the service for zeroconf

  • @theodorealenas3171
    @theodorealenas3171 Před 2 lety +11

    It's odd to me that these can be useful. Linux feels infinite.

    • @vince6792
      @vince6792 Před 2 lety +3

      Wonderful statement describing Linux fascination and curiosity.

  • @emacsking4310
    @emacsking4310 Před 2 lety +1

    Love from Denmark DT

  • @0__alfie__0
    @0__alfie__0 Před 2 lety +2

    I wonder why uname maybe unix name?

    • @DistroTube
      @DistroTube  Před 2 lety +5

      But GNU's Not Unix . :D

    • @paulg3336
      @paulg3336 Před 2 lety +1

      user name?
      edit: "uname (short for unix name) is a computer program in Unix"
      -Wikipedia

    • @0__alfie__0
      @0__alfie__0 Před 2 lety +3

      @@paulg3336 Oh nice I was right

    • @dougtilaran3496
      @dougtilaran3496 Před 2 lety

      @@DistroTube I recall in the old days is was called unix/PG

  • @davidprock904
    @davidprock904 Před 2 lety

    Replying here cause this is your latest video, but about Appimage, I want to get back into gentoo, and I see this solving my annoyances. But I want to make an app image of what I Installed that better/perfectly matches my hardware, and then install and move on to the next,.
    So everything that can NOT run as an appimage... install that to stay, but everything else temporarily to be put into an appimage.
    But I need to know if an app creates/modify a configuration file ETC. Will it be permanent ? If it's permanent, will the change stay within the single appimage file, or will it be stored outside of it?
    Side note if all changes are lost, it would be great for browser privacy, close or open another instance for each individual website, to stop cross tracking... or what ever its called.
    Also when creating it, is there a way for it to automate all the applications dependency, and those dependency on top of others and grab them all, or do you manually have to copy everything

  • @nrdfoss
    @nrdfoss Před 2 lety +1

    how did you manage to stretch this video out this long lol

  • @shriram5494
    @shriram5494 Před 2 lety

    is whoami just syntactic sugar for echo $USER ?

  • @keltyll
    @keltyll Před 2 lety +1

    Is it "safe" to change from time to time the hostname via /etc/hostname though ?

    • @BurgerKingHarkinian
      @BurgerKingHarkinian Před 2 lety +3

      Not sure but on systemd-based distros you probably want to use the hostnamectl command.

    • @KyleRassweiler
      @KyleRassweiler Před 2 lety +1

      The hostname is used in the /etc/hosts file as well (this is where the -i flag gets the ip from) so it would need changed there if done manually.
      I'm sure there's a better way to change this all but I just do it manually.

  • @pwall
    @pwall Před 2 lety

    doesnt uname -a give you the hostname?

    • @JamesWoodard1222
      @JamesWoodard1222 Před 2 lety

      Yes. In the second field.
      Also, uname -n (or --node) prints only the network nodes hostname.'
      Maybe this is part of the reason 'hostname' isn't included in coreutils on Arch Linux?

  • @siaal5001
    @siaal5001 Před 2 lety +2

    dirname and basename can be replaced with bash parameter expansion ${0%/*} and ${##*/}/

  • @sotecluxan4221
    @sotecluxan4221 Před 2 lety

  • @AnthonyGarnerAnthonyFJGarner

    You should show people how to quit VIM. I'm a new user following along and had to google it. Just a thought!

  • @xrafter
    @xrafter Před 2 lety

    *name

  • @rizkyadiyanto7922
    @rizkyadiyanto7922 Před 2 lety

    third

  • @mrlithium69
    @mrlithium69 Před 2 lety

    SHELL not SHILL

  • @QuoteVG
    @QuoteVG Před 2 lety

    10:00 Missed opportunity to demonstrate the thing you're talking about, instead of just talking about it.

  • @joaopedroalbernaz
    @joaopedroalbernaz Před 2 lety

    "GNU/Linux"