Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The target is not to list temp/run*.* files. The target is to understand why the second command does not work.

First command:

find . \( -name 'temp' \) -print0 | xargs -0 -L 1 -I datafind ls -ltr datafind

list all the files inside temp folders from actual directory

Second command:

find . \( -name 'temp' \) -print0 | xargs -0 -L 1 -I datafind ls -ltr datafind/run*.*

gives cannot access error on every directory that worked with the previous command.

I searched and read man pages and examples but I can not find why the second command does not work. Any clue, please?

share|improve this question
Not asked, but why not filter at find time? find . ! \( -name 'run*' \) -print – Hennes Oct 2 '13 at 16:17
Because there are other 'run*' files on other folders, I do not want to see. Also, please, target is: understand why second command does not work. – jose Oct 2 '13 at 16:21
up vote 4 down vote accepted

The confusion is that wildcard characters such as * and *.* are evaluated by the shell when you type the command.

Therefore datafind/run*.* is evaluated by the shell and would be replaced by the filenames which match that, but it does not find any files that match. Therefore datafind/run*.* is given to the xargs command and then it passes that right through to the ls command.

The ls command does not understand wildcard characters so it just takes its input and tries to find a file with that name. There is no file with the name run*.* so you get an error No such file or directory.

share|improve this answer
Ohhh. Do you mean ls work is only print the data that shell has gathered? Never suspected but it matches with result :) Thank you very much. – jose Oct 2 '13 at 16:39
find . ( -name 'temp' ) -print0 | xargs -0 -L 1 -I datafind sh -c "ls -ltr datafind/run*.*" Perfect. Many thanks again – jose Oct 2 '13 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .