Essential Linux Commands - Cat, Tac and Tee

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 มี.ค. 2022
  • In this video, I will discuss three of the basic command line utilities: cat, tac and tee. These commands are useful for printing the contents of files to standard output and concatenating files. Very handy tools to know whether using the shell interactively or scripting.
    REFERENCED:
    ► distro.tube/man-org/man1/cat.... - cat
    ► distro.tube/man-org/man1/tac.... - tac
    ► distro.tube/man-org/man1/tee.... - tee
    WANT TO SUPPORT THE CHANNEL?
    💰 Patreon: / distrotube
    💳 Paypal: th-cam.com/users/redirect?even...
    🛍️ Amazon: amzn.to/2RotFFi
    👕 Teespring: teespring.com/stores/distrotube
    DONATE CRYPTO:
    💰 Bitcoin: 1Mp6ebz5bNcjNFW7XWHVht36SkiLoxPKoX
    🐶 Dogecoin: D5fpRD1JRoBFPDXSBocRTp8W9uKzfwLFAu
    📕 LBC: bMfA2c3zmcLxPCpyPcrykLvMhZ7A5mQuhJ
    DT ON THE WEB:
    🕸️ Website: distrotube.com/
    📁 GitLab: gitlab.com/dwt1
    🗨️ Mastodon: fosstodon.org/@distrotube
    👫 Reddit: / distrotube
    📽️ LBRY/Odysee: odysee.com/@DistroTube:2
    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.org/
    🗒️ Doom Emacs: github.com/hlissner/doom-emacs
    Your support is very much appreciated. Thanks, guys!
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 83

  • @Phydoux2112
    @Phydoux2112 2 ปีที่แล้ว +20

    Looks like you have a much more stronger and complicated password on your main machine there. Excellent video! I love these shell command videos. This one was really interesting. Thanks!

    • @jyvben1520
      @jyvben1520 2 ปีที่แล้ว

      so you do "cat ./example_file.iso > /dev/sdb", it may be cleaner but is it faster (no blocksize set) ?

    • @Phydoux2112
      @Phydoux2112 2 ปีที่แล้ว +1

      @@jyvben1520 that sounds dangerous. I'd read up on mounting iso files with cat a bit more before trying that one. I wonder if tac would mount it in reverse order...

  • @reality-drift122
    @reality-drift122 2 ปีที่แล้ว +13

    You have been such a large help in my Linux endeavors!! Thank you!

    • @pleaseenteraname1215
      @pleaseenteraname1215 2 ปีที่แล้ว +1

      I second this sentiment this small mundane commands give way to learning big ones.

  • @motozappa225
    @motozappa225 2 ปีที่แล้ว +16

    cat is also useful to write/burn isos to drives, so it's a more efficient and clean alternative to dd or the other gui utilities out there

    • @pleaseenteraname1215
      @pleaseenteraname1215 2 ปีที่แล้ว +1

      so to do this I just cat out my iso to /dev/sd*? also why is dd not clean?

    • @xrafter
      @xrafter 2 ปีที่แล้ว

      @@pleaseenteraname1215
      Because dd stands for "dirty delete".

    • @xrafter
      @xrafter 2 ปีที่แล้ว

      @@pleaseenteraname1215
      But no, I don't think cat is a better alternative than dd.
      Read more about it here >>> [provide link]

    • @pleaseenteraname1215
      @pleaseenteraname1215 2 ปีที่แล้ว +1

      @@xrafter Your link is invalid :(

    • @xrafter
      @xrafter 2 ปีที่แล้ว

      @@pleaseenteraname1215
      Ok.

  • @OldieBugger
    @OldieBugger 2 ปีที่แล้ว +8

    Tac & Tee sound quite like the little programs I've written for some specific use, often a single use. Or sometimes I've used them twice.

  • @CostaKazistov
    @CostaKazistov 2 ปีที่แล้ว +3

    Top notch examples!
    More of these videos, please.

  • @maciejszostakiewicz6883
    @maciejszostakiewicz6883 2 ปีที่แล้ว +7

    Hah LOL, fresh video from 20 sec ago!! Yeah!!

  • @linuxdude5742
    @linuxdude5742 2 ปีที่แล้ว +4

    I have never heard of tac before your video

  • @Appalling68
    @Appalling68 2 ปีที่แล้ว +1

    Excellent tutorial, especially (at least for me) the "tee" part.

  • @nxzthelinuxguy5192
    @nxzthelinuxguy5192 2 ปีที่แล้ว +3

    In love with your scripting tutorials

  • @jamboyman
    @jamboyman 2 ปีที่แล้ว +6

    The tee content is missing a really cool addition that I've only needed once so far. Using process substitution you can split pipes to multiple commands (ksh/bash/zsh):
    Uname | tee >(cowsay) >(grep a) ... >(Command n) | grep b
    All the commands will be run with the same input
    Think you can do the same process substitution in fish by just doing:
    command 1 | tee (command 2) (command 3)

  • @spacebuffer
    @spacebuffer 2 ปีที่แล้ว +9

    Loving these videos!

    • @DistroTube
      @DistroTube  2 ปีที่แล้ว +2

      More to come!

    • @pleaseenteraname1215
      @pleaseenteraname1215 2 ปีที่แล้ว +1

      @@DistroTube Thank you so much keep this up this is very necessary for new users and I love how useful linux has been.

  • @Handy-Handy
    @Handy-Handy 2 ปีที่แล้ว

    thx man! the command tee I have used far too rarely :)

  • @whiskeylinux
    @whiskeylinux 2 ปีที่แล้ว +2

    Dude I never knew about tac, so much fun lol

  • @jidun9478
    @jidun9478 ปีที่แล้ว

    Thank you. Excellent tutorial.

  • @user-op1nb7fq6s
    @user-op1nb7fq6s ปีที่แล้ว

    This is genius!
    I need more!

  • @michalbotor
    @michalbotor 11 หลายเดือนก่อน

    sudo tee trick is really cool
    thx

  • @MarkusHobelsberger
    @MarkusHobelsberger 2 ปีที่แล้ว +2

    I actually had the very last problem recently. I just sledgehammered it with su, but the tee solution would have been much more elegant :)

  • @MasterHigure
    @MasterHigure 2 ปีที่แล้ว +9

    You explained > and >>, but not |. Of the three, I would think that's the one that most needs explaining to beginners. Also, I didn't know command-line arguments really count as stdin, I thought that was only when programs ask for input while running (the way a newbie's second program after hello world, the one that echoes your name back at you, would typically work).

    • @DistroTube
      @DistroTube  2 ปีที่แล้ว +11

      Yea, 'ls' wasn't a good example of what stdin is. I should have used something like 'cat < file' where cat takes stdin as an argument. Kinda ironic that I didn't use 'cat' as an example since this video was about 'cat'. ;)

    • @WildVoltorb
      @WildVoltorb 2 ปีที่แล้ว

      Are you going to explain that or what

    • @MasterHigure
      @MasterHigure 2 ปีที่แล้ว +4

      ​@@WildVoltorb My understanding, after using it here and there for a decade and a half, but never actually diving deep into any kind of documentation or such, is as follows:
      When you run a program that stops and waits for input from you before it continues (often a yes / no confirmation, but also other things like games played in the terminal), that input comes into the program through stdin. Many common command line tools take input either in the form of command line arguments or from stdin.
      grep, for instance, can take a filename and search through that file for whatever pattern you're looking for, and print each such line it finds. Or it can take input from stdin and look through that in exactly the same way.
      The | symbol takes the stdout output from one program, and rather than printing it to the terminal it feeds it into the stdin input of another program. In such "piped" commands, cat is a typical sender program and grep is a typical receiver program (although in chained piped commands, it can do both roles, and act as a filter). In fact, "cat filename | grep pattern" is, as far as I can tell, equivalent to "grep pattern filename".

  • @davidpetersonharvey
    @davidpetersonharvey 2 ปีที่แล้ว

    I use tee within mysql to run reports for clients. It's very handy.

  • @phanindratube10
    @phanindratube10 ปีที่แล้ว

    Tee rocks!

  • @xrafter
    @xrafter 2 ปีที่แล้ว

    15:02 now open that file using vim or nano.
    You will see all of thaf weird "/003" escapes that got interepted by the shell.

  • @cuttlefishn.w.2705
    @cuttlefishn.w.2705 2 ปีที่แล้ว

    md5sum or shasum to see if two files have exactly the same contents, without having to open up and read them individually. The hash should be the same between .bashrc and newfile.txt.

  • @xrafter
    @xrafter 2 ปีที่แล้ว

    Hello DT, in the cat example, are you sure the newfile.txt and bashrc are the same with order difference?

  • @agneaybnair9519
    @agneaybnair9519 2 ปีที่แล้ว +1

    Hey DT, I feel that the classic "hello world" statement should be replaced by "Hi Mom!" Do you agree with me?

  • @staswisniewski4101
    @staswisniewski4101 2 ปีที่แล้ว

    Quick question - will You put link/direct command to change color of cursor in terminal?

  • @amerikraine3401
    @amerikraine3401 ปีที่แล้ว

    I remember when I was new and trying to read the inside of a file and the answer was "cat". Lol

  • @lukevideckis2260
    @lukevideckis2260 2 ปีที่แล้ว

    Hey DT, do a video on the 'bat' command - a nice alternative to cat

    • @nxzthelinuxguy5192
      @nxzthelinuxguy5192 2 ปีที่แล้ว +1

      He probably already did it in his rust programs video

  • @manofnorse
    @manofnorse 2 ปีที่แล้ว

    First of all, it has to be mentioned that the kind of redirection with file descriptors you show, only applies to those shells, who have mainly inherited from the Bourne shell, while other shells might have other notations for that.
    The other points:
    No, "cat 0

  • @sotecluxan4221
    @sotecluxan4221 2 ปีที่แล้ว

  • @synen
    @synen 2 ปีที่แล้ว

    What are some examples where TAC is useful? Thank you.

  • @laughingvampire7555
    @laughingvampire7555 ปีที่แล้ว

    cat goes in pair with split

  • @kadensharpin2156
    @kadensharpin2156 2 ปีที่แล้ว

    would "sudo -u root echo 1 > /proc/sys/kernal/sysrq" work as well?

  • @SB-qm5wg
    @SB-qm5wg 2 ปีที่แล้ว +1

    I'll do anything to not have to use awk. I'll sacrifice a live chicken.

  • @econ5887
    @econ5887 2 ปีที่แล้ว

    For vim: sudoedit instead of tee

  • @mohamedalichabani6775
    @mohamedalichabani6775 2 ปีที่แล้ว +1

    How do you get colors in you man pages tho ?

    • @ahahahabmbc1075
      @ahahahabmbc1075 2 ปีที่แล้ว

      I think Zsh automatically colors man. For bash, you need to write a function. Quick web search will give you the answer

    • @DistroTube
      @DistroTube  2 ปีที่แล้ว +2

      i use 'bat' for my manpager instead of 'less.' I've done a video about changing your manpager awhhile back.

  • @paupereira1269
    @paupereira1269 2 ปีที่แล้ว

    What widget do you use to get the kernel version?

    • @othernicksweretaken
      @othernicksweretaken 2 ปีที่แล้ว

      uname -r

    • @paupereira1269
      @paupereira1269 2 ปีที่แล้ว

      @@othernicksweretaken yes i know the command but how can you put that in a widget?

    • @othernicksweretaken
      @othernicksweretaken 2 ปีที่แล้ว

      @@paupereira1269 I have never done widget development because I don't require a GUI or desktop.
      I can remember that some 25 years ago I scripted GUI / widget stuff in Tcl (tickle), and a little later in Perl::Tcl.
      But I have long forgotten what I did back then.
      I would suggest to read the docs and man/info pages of the respective API that you are using.
      They might have implemted the uname syscall of libc.

  • @AeriaVelocity
    @AeriaVelocity 2 ปีที่แล้ว

    Don't forget about eet

  • @Joanyan
    @Joanyan 2 ปีที่แล้ว +1

    it's weird that people are using cat to print to standard output instead of using < followed by the filename

    • @DistroTube
      @DistroTube  2 ปีที่แล้ว +1

      "< filename" is not a legit command in Bash, the default system on every Linux distro and almost always the default user shell. "< file" is also not a valid command in Fish. So....there's that.

    • @Joanyan
      @Joanyan 2 ปีที่แล้ว

      @@DistroTube oh I see. I original found out about < in a luke smith video from 2019, and it worked as he said on zsh so I thought it was universal.
      after testing it in bash now I see that it's not a bash command

    • @Joanyan
      @Joanyan 2 ปีที่แล้ว

      th-cam.com/video/82NBMvx6vFY/w-d-xo.html here is the video(I put it in a separate comment since yt sometimes automatically removes comments with links in them)

  • @ArtemPelenitsyn
    @ArtemPelenitsyn 2 ปีที่แล้ว +1

    Your light is a bit off: some of the face is in shadow.

  • @kychemclass5850
    @kychemclass5850 2 ปีที่แล้ว

    >> for overwrite and > for append would have been much safer !!

  • @livingcodex9878
    @livingcodex9878 2 ปีที่แล้ว +1

    おはようございます

  • @tamoozbr
    @tamoozbr 2 ปีที่แล้ว +2

    Why do you have a terminal rickroll?

    • @DistroTube
      @DistroTube  2 ปีที่แล้ว +1

      Why wouldn't I have a terminal rickroll?!

    • @tamoozbr
      @tamoozbr 2 ปีที่แล้ว +1

      @@DistroTube you're right

  • @KangJangkrik
    @KangJangkrik 2 ปีที่แล้ว

    Try this command
    cat $(which cat)

  • @jangofett132
    @jangofett132 2 ปีที่แล้ว +4

    frist

  • @thefossenjoyer3346
    @thefossenjoyer3346 2 ปีที่แล้ว +1

    First!

  • @dougtilaran3496
    @dougtilaran3496 2 ปีที่แล้ว

    tac is arabic. TD HUBP

  • @ShaunakHub
    @ShaunakHub 2 ปีที่แล้ว +2

    tac should have been named dog...
    Linux devs have no sense of humour!

  • @piadas804
    @piadas804 หลายเดือนก่อน

    Those are GNU commands, not Linux commands.

  • @francescopremsolidoro3858
    @francescopremsolidoro3858 2 ปีที่แล้ว +1

    tsk, tsk. The most basic use of cat is the "Useless use of Cat"

  • @ebiscaia
    @ebiscaia 2 ปีที่แล้ว

    So if am I right "cat .bashrc && cat .bashrc > newfile.txt" == "cat .bashrc | tee newfile"?