Can anyone tell me what this command means?
I've seen it in a tutorial but can't get it well.
find . -type f | xargs file
Can anyone tell me what this command means?
I've seen it in a tutorial but can't get it well.
find . -type f | xargs file
find . -type f
finds all files of type f
in the current directory and its sub-directories recursively where the f
means that it finds only files including hidden files. find . -type f
is piped by the pipe character |
and to execute using xargs
another command ( file
) . The file
command tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic tests, and language tests. The first test that succeeds causes the file type to be printed.
find . -type f | xargs file
interprets the spaces between words in a filename as separators, so it returns multiple results of file
for the same file if its filename contains one or more spaces. This is an unwanted result for most users who want file
to return only a single result for each file that is found by the find
command, even if the file contains one or more spaces in its name. To correct this unwanted result change the command as follows:
find . -type f -exec file {} +
find . -type f -exec file {} +
outputs the same results as
find . -type f | xargs file
except that it returns only one result for each file that is found by find
, even if the file contains one or more space characters in its name.
This command finds all regular files and runs file
command on the found files.
Actually it shows types of files for all regular files in the current directory.
man find
andman xargs
in a terminal, or google it. – Soren A Jan 14 '21 at 12:40find . -type f
finds all files (-type f) from current directory (.) and down. This is piped to the xarg command, that runs the commandfile with the result as argument ... showing the content type of the found files. – Soren A Jan 14 '21 at 12:44