PLAY PODCASTS
'xargs' - execute command lines from standard input - Video Man Pages

'xargs' - execute command lines from standard input - Video Man Pages

DistroTube on Odysee

February 28, 20269m 48s

Audio is streamed directly from the publisher (player.odycdn.com) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.

Show Notes

thumbnail

'xargs' takes the output of one command (or contents of a file), converts it into a list of arguments, and passes that list to another command to execute.

- Run a command using the input data as arguments:
command1 | xargs command2

- Count lines in multiple files:
ls *.txt | xargs wc -l

- Cat a file and use the input data as an argument:
cat file | xargs
NOTE If no xargs command is given, xargs uses 'echo' as the command.

- The same as above except it executes the command once per argument (-n 1):
cat file | xargs -n 1

- Create 10 sequential .txt files. The '-I {}' symbolizes all the input:
seq 10 | xargs -I {} touch {}.txt

- Delete files with '.log' extension found by 'find'. The -print0 in 'find' and -0 in 'xargs' use a null character as a delimiter, ensuring filenames with spaces or special characters are handled correctly.
find . -name "*.log" -print0 | xargs -0 rm -f

- Find and delete all backup files (.bak). The '-p' option is useful for destructive operations, as it displays the command to be executed and asks for user confirmation (y/n).
find . -type f -name "*.bak" | xargs -p rm

- The '-d' option sets the delimiter (spaces by default):
ls | xargs -n 1 (Files/directories with spaces are a problem.)
ls | xargs -n 1 -d \n (Uses new line as delimiter and problem solved!)

- xargs can print (-a) the contents of a file to stdout. We can use '-p' to prompt for 'y/n' before executing. We can use '-r' to only execute if stdin is not empty.
xargs -a 1.txt
xargs -p -a 1.txt
xargs -r -p -a 1.txt

REFERENCED:
โ–บ https://gitlab.com/dwt1/vidman

WANT TO SUPPORT THE CHANNEL?
๐Ÿ’ฐ Patreon: https://www.patreon.com/distrotube
๐Ÿ’ณ Paypal: https://www.paypal.com/donate/?hosted_button_id=MW3ZFGS8Q9JGW
๐Ÿ›๏ธ Amazon: https://amzn.to/2RotFFi
๐Ÿ‘• Teespring: https://teespring.com/stores/distrotube

DT ON THE WEB:
๐Ÿ•ธ๏ธ Website: http://distro.tube
๐Ÿ“ GitLab: https://gitlab.com/dwt1
๐Ÿ—จ๏ธ Mastodon: https://fosstodon.org/@distrotube
๐Ÿ‘ซ Reddit: https://www.reddit.com/r/DistroTube/
๐Ÿ“ฝ๏ธ Odysee: https://odysee.com/@DistroTube:2

FREE AND OPEN SOURCE SOFTWARE THAT I LIKE:
๐ŸŒ Brave Browser - https://brave.com/
๐Ÿ“ฝ๏ธ Open Broadcaster Software: https://obsproject.com/
๐ŸŽฌ Kdenlive: https://kdenlive.org
๐ŸŽจ GIMP: https://www.gimp.org/
๐Ÿ’ป VirtualBox: https://www.virtualbox.org/
๐Ÿ—’๏ธ Doom Emacs: https://github.com/hlissner/doom-emacs

Your support is very much appreciated. Thanks, guys!
...
https://www.youtube.com/watch?v=tUkQcvytVtw