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
  • 3
    Take a look at the maual. Type `man find` and `man xargs` in a terminal, or google it. – Soren A Jan 14 '21 at 12:40
  • For reference, from which tutorial did you find this command, and have you tried running it? – Umlin Jan 14 '21 at 12:43
  • 1
    But anyways: `find . -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
  • You can also take a look at the following question: [How can I get help on terminal commands?](https://askubuntu.com/questions/991946/how-can-i-get-help-on-terminal-commands) – Dan Jan 14 '21 at 13:21

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
  • 110,292
  • 102
  • 269
  • 299
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
  • 88,764
  • 91
  • 205
  • 313