0

I have a directory that contains 800 subdirectories named disp-001 ... disp-800. All these sub-directories need to contain a specific file say stdout. One among them does not contain the file and I need to find the folder that does not have the file. If I try

find . -name "stdout"

it returns me the values of all files, but they are not ordered from 001 to 800, which makes it very difficult for me to identify the folder. Is there a way to order the output such that they are ordered numerically?

NOTE:

I'm leaving this question unedited to demonstrate (atleast to myself) a classic XY problem. All I needed was to identify directories not containing a particular file, but instead this question was about a particular attempted solution to the problem. The solution for finding a directory that does not contain a particular file is provided here.

  • Is your question about finding the directory that does not have a given file, or about sorting the output of find? – Jeff Schaller Sep 11 '15 at 16:13
  • printf '%s\n' dir*/stdout – Stéphane Chazelas Sep 11 '15 at 16:13
  • 1
    See also zsh's printf '%s\n' dir*(/^e:'[ -e $REPLY/stdout ]':) – Stéphane Chazelas Sep 11 '15 at 16:14
  • Sorry its a XY problem. I need the directory that does not contain the file. I will rephrase the question – WanderingMind Sep 11 '15 at 16:15
  • +1 to Stephane's zsh answer for the trailing (functional!) :) – Jeff Schaller Sep 11 '15 at 16:21
3

Personally, I would use the shell for that instead:

$ for dir in disp-{001..800}; do [ -f "$dir"/stdout ] || echo "$dir"; done
disp-389

In my test, disp-389 was the only directory lacking that file and so the only one printed.

If your shell doesn't support that form of brace expansion, just use for dir in disp* or, assuming you want to check all directories, for dir in */.

  • That assumes zsh or a recent version of bash (4.0 or above). – Stéphane Chazelas Sep 11 '15 at 16:34
  • @StéphaneChazelas fair enough, edited to add a more portable way. – terdon Sep 11 '15 at 16:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.