Linux – Difference between xargs /bin/ls and exec ls

findlinuxmacosxargs

Hi this may be a very newbie question, but why doesnt the xargs /bin/ls work in this case? I thought it was supposed to be faster? Also what are those /fd/3 directories?

sh-3.2# find / -name 'GOALS*' -exec ls -l {} \;
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
.... This returns me the expected result....

However this returns the whole list of files in the directory

sh-3.2# find / -name GOALS* -type f | xargs /bin/ls -l

I am on a MacOS.

Best Answer

  1. you need to quote the * in the second find command,

  2. the /dev/fd/* are devices which corresponds with stdin, stdout, stderr etc. thouse devices are simlinked and are different for each process,

  3. the -type f says, the result has to be regular file, thus the /dev/fd/* are not in the result as they are block devices,

  4. the xargs ls -l does the same as your ls -l {}... I even doubt the better performance in this case, but xargs is smarter and there are reasons to use it, eg. correct handling of files with whitespaces inside it,

If you are debugging the second version of your find, first of all see the output w/o the | xargs ls -l part

Related Question