0

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

2 Answers2

3

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.

karel
  • 114,770
1

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.

Pilot6
  • 90,100
  • 91
  • 213
  • 324