Xargs Should Be In Your Command Line Toolbag

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ก.ค. 2021
  • Xargs is an important shell utility to know because it allows you to execute to pass standard input as an argument to another command. While many command line programs allow standard input to be used as a parameter (things like grep, sed, awk etc.), many other programs do not allow for this (such as echo and rm). This is where Xargs comes in handy.
    REFERENCED:
    ► man7.org/linux/man-pages/man1...
    WANT TO SUPPORT THE CHANNEL?
    💰 Patreon: / distrotube
    💳 Paypal: www.paypal.com/cgi-bin/webscr...
    🛍️ Amazon: amzn.to/2RotFFi
    👕 Teespring: teespring.com/stores/distrotube
    DONATE CRYPTO:
    💰 Bitcoin: 1Mp6ebz5bNcjNFW7XWHVht36SkiLoxPKoX
    🐶 Dogecoin: D5fpRD1JRoBFPDXSBocRTp8W9uKzfwLFAu
    📕 LBC: bMfA2c3zmcLxPCpyPcrykLvMhZ7A5mQuhJ
    SOCIAL PLATFORMS:
    🗨️ Mastodon: distrotoot.com/@derek
    👫 Reddit: / distrotube
    📽️ LBRY/Odysee: odysee.com/$/invite/@DistroTu...
    DT ON THE WEB:
    🕸️ Website: distrotube.com/
    🐿️ Gemini Capsule: gemini://distro.tube
    📁 GitLab: gitlab.com/dwt1
    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/
    🎵 Ardour: ardour.org/
    💻 VirtualBox: www.virtualbox.org/
    🗒️ Doom Emacs: github.com/hlissner/doom-emacs
    Your support is very much appreciated. Thanks, guys!

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

  • @first-thoughtgiver-of-will2456
    @first-thoughtgiver-of-will2456 2 ปีที่แล้ว +138

    I've been writing bash scripts for years now and never bothered to thoroughly read the documentation. I have always used an inferior work around for this thank you for showing me the formal solution.

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

    xargs is a true lifesaver when it's needed. One key example is when you have a tool that needs to run on every file in a directory. Using ls and xargs with -n 1 can really blast out the results compared to trying to bash for loop it or something. The problem is people don't even know about it to consider it as an option.

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

    Nice video, but recommending against using `find -exec` doesn't make sense. The reason it took so long is because you instructed it to run 1,000 individual rm commands by putting a semicolon at the end; replace that with a plus sign (or just use the -delete option in this case) and find will bulk delete those files in no time with no need for xargs.

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

    that `find -exec` vs `xargs` speed, isnt that just that `xargs` puts it all in one line and executes one time with 1000 arguments instead of one by one? i wouldnt call `find -exec` slow just for that, at least that generalization doesnt feel right

  • @BryonLape

    Been a user of Unix since 1987 and never learned a thing about shill. I feel so ignorant.

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

    Why is xargs so much faster than find?

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

    TIL the -t, -n, and -P flags

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

    Really nice.

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

    Thanks for this

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

    Comment to bring this video to the tops

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

    Just a tip, if you are trying to create a bunch of sequentially numerated files with touch, you can use bash ranges {} syntax, like "touch {1..1000}".. It's really convenient, and it works with other types of sequences (a..z), and you can even pass a step in which next item will be incremented :)

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

    Hey DT, your comparison of "-exec" and "xargs" wasn't entirely fair.

  • @davidh.4944
    @davidh.4944 ปีที่แล้ว +2

    Rather than xargs, I've recently been learning how to use GNU parallel, and I love it. Its syntax is more cumbersome to work with than xargs, but it's also much more powerful. You can interleave multiple inputs (e.g. from stdin and files at the same time), position the incoming strings in any order you want in your command, and modify them before use (e.g. to remove file paths). You can even distribute jobs over multiple machines via ssh.

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

    XARGS is one of those insanely useful tools. It's something in my toolbox that I use EVERY day when I manage any one of the hundreds of servers I could be dealing with each day.

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

    Thank you DT for all what you do.

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

    Love the new bash tuts! Looking forward to more

  • @genkiferal7178

    The lighting in this video is flattering for your blue or green eyes.

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

    These command line utility videos are amazing. Thank you for the content.

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

    This was an incredibly well written and produced video. Really spectacular job running down this command.

  • @jezbon
    @jezbon  +1

    It's still amazing that decades after shell and all these little tools were created for Unix that they're still insanely awesome. Still. That's just mindblowing. They were designed as the best operating system/logic building blocks of all time. Just a wonder of human ability to have nailed this.