>>101219516
>qrd for a noob?
Sure, ever wanted to execute a single command for a lot of files scattered around your hard drive?, then xargs is for you
Let's say I have multiple files with a file pattern that I want to know their file type, and they're scattered throughout my home folder, to do it manually I'd have to:
>navigate to every single folder
>look for the file with pattern
>call the command
Example:
File pattern: pattern1.mp4, pattern2.mp4... etc
Folder: /home/anon
So, let's split the job in 2:
>1. find all files with pattern
find /home/anon -name ''pattern*.mp4"
>2. call comand to know the type of a single file
file /home/anon/folder1/pattern1.mp4
Doing it manually will take ages, so instead I'll take 1.'s output and pass it to xargs, then xargs will execute the find command on each one of them.
find /home/anon -name ''pattern*.mp4" | xargs -n 1 -I {} file {}
Explanation:
>find /home/anon -name ''pattern*.mp4"
This is the standard find command, it'll search recursively for all files with pattern
> |
this is a pipe operation, it'll take the output of find and pass it to the next command
>xargs -n 1 -I {} file {}
This is where magic happens
>-n 1
This tells the number of arguments
>-I {}
This is a way to tell xargs that "{} is a single element that the previous command will send us"
>file {}
This is instruction 2. but expanded N times, it'll execute file for each item found
idk if that makes sense