-2

I would like to inquire about an error message that I get when I run the command "find". In the following paragraph, I will explain what I am trying to accomplish.

I have a parent folder. Inside this folder there are many subfolders. Inside each subfolder there are plenty of sub-sub folders. I would like to list the sub-sub folders that contain a specific number of files. I ran for loop as follows:

#!/bin/bash
in=PATH_TO_THE_PARENT_FOLDER

for i in ${in}/*; do
find ${i} -maxdepth 1 -type d -print0 | xargs -0 -I {} sh -c 'echo -e $(find {} | wc -l) {}' | sort -n | grep -w 69 | awk '{print $2}' #69 represent the total number of files within a folder
done

This code output the following error message sh: MPR_Range: No such file or directory. I Googled looking for an explanation for what sh: MPR_Range means, but I couldn't find any answer.

3

Assume you have a file called foo&bar. xargs will now run the command

sh -c 'echo -e $(find foo&bar | wc -l) foo&bar' 

That runs echo and find in the background, and two copies of bar. Similarly for foo;bar, and $(bar).

Don't use {} in the argument to sh -c, instead, give the filename as a separate argument, i.e.

... |xargs sh -c 'echo -e $(find "$1" | wc -l) "$1"' sh {} | ...

In addition, you could use find -exec instead of xargs:

find -type d -exec sh -c 'echo ...' \; 

I'm also not exactly sure if the sort is necessary, if you running grep to find lines with particular numbers anyway.

  • 1
    @goro, of course, for that to produce that error, you'd need to have some file with MPR_Range and other appropriate characters in the file name, but that looks like it would be the most likely explanation here – ilkkachu Jun 6 '18 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy