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

I want to search for all .exe files greater than 200 kB or smaller than 120 kB in the current folder and its subfolders. Then I want to move them to another folder called "folder" and execute in this folder the file called "executable.exe" infinitely and show some information about its memory consumption.

Any ideas?

I'm using Linux Mint. I used the find command to search for ".exe" files, per Indrek's answer.

find . -name "*.exe" \( -size +200k -o -size -120k \)

Now what I want to do is to move those file to another folder called "myFolder", and after this I have to execute any file in this folder called "MyExec.exe"

share|improve this question
up vote 5 down vote accepted

Update: since you specified that you're using Linux, most of the options I originally described are irrelevant, except for the find command:

find . -name "*.exe" \( -size +200k -o -size -120k \)

To move all matching files to another directory, you have several options.

  1. Use the -exec argument, which (as the name suggests) allows you to execute a given command for each matched file. See man find for more information.

    find . -name "*.exe" \( -size +200k -o -size -120k \) -exec mv {} ./myFolder \;

    Here, {} is replaced with the name of each file as it's processed. See also man mv for information on that command.

  2. Alternatively, wrap the entire find command in backticks and pass it as the first argument to mv:

    mv `find . -name "*.exe" \( -size +200k -o -size -120k \)` ./myFolder
  3. You can also accomplish the same thing by piping the output of the find command to xargs:

    find . -name "*.exe" \( -size +200k -o -size -120k \) | xargs -i mv {} ./myFolder

Once again, {} is replaced with the current filename. See man xargs for more information.

Finally, to execute MyExec.exe (I'm assuming you're using Wine for this):

wine ./myFolder/MyExec.exe

I'll preserve my original answer below, in case someone needs to do something similar on Windows.

There's several options, depending on how you want to execute your search.

  1. Since you mention .exe files, I'm assuming you're on Windows. The first option would be using the search box in Windows Explorer. Just navigate to the folder where you want to start your search, hit F3 and enter the following search query:

    *.exe (Size:<120kB OR Size:>200kB)

    For more information, see Advanced tips for searching in Windows.

    To move the files, simply select them and drag&drop (or cut&paste) them to the target folder.

  2. If you want to do this from the command line (for instance, if the process needs to be automated):

    forfiles /m *.exe /s /c "cmd /c if @fsize GTR 204800 (echo @path) else if @fsize LSS 122880 (echo @path)"

    For more information, see the documentation for the forfiles and if commands.

    To move the files, replace echo @path with move @path C:\destination\folder.

  3. Alternatively, Powershell provides a cleaner syntax:

    Get-ChildItem -Recurse | Where-Object { $_.Extension -eq ".exe" -and ( $_.Length -gt 204800 -or $_.Length -lt 122880 ) }

    For more information, see the documentation on the Get-ChildItem and Where-Object cmdlets. Note the file sizes are in bytes (204800 B = 200 kB, and 122880 B = 120 kB).

    To move the files, pipe the output of the above to the Move-Item cmdlet.

  4. Finally, if you have Cygwin or some other Unix-compatible shell available (which I assume you do, from the "bash" tag), you can also use the find command:

    find . -name "*.exe" \( -size +200k -o -size -120k \)

    For more information, see man find.

    To move the files, use the -exec argument.

As for the second part of your question, maybe you could elaborate what you're trying to achieve with executing "executable.exe" and how it relates to the finding and moving of other .exe files.

share|improve this answer
Thank you, I used the 4th solution. can you see my EDIT !! – wassim-azirar May 28 '12 at 23:21
You are awesome, thank you very much – wassim-azirar May 28 '12 at 23:39
@dotNET I updated my answer to add several options that work in Linux. Hope this helps. – Indrek May 28 '12 at 23:56

The below Bash code should move the files. I don't know what you mean by "execute in this folder the file 'executable.exe' infinitely". You may be able to use Cygwin's /proc filesystem to examine the memory usage of executable.exe.

find . -type f |
    while read FILE
        set -- $(/bin/ls -l "$FILE")
        [ "$5" -lt 120000 -o "$5" -gt 200000 ] && mv "$FILE" folder
echo "Files copied!"
if cd folder
    echo "Failed to cd into folder!" >&2

BTW, my numbers are not exactly 200 kilobytes and 120 kilobytes. Feel free to do the math yourself (e.g., 200 * 1024 and 120 * 1024) to get exact byte counts.

share|improve this answer
I don't know how you could make so much sense about this post :D – sinni800 May 28 '12 at 22:07
Thanks Fran, your solution works fine for me, I need just to do one last thing : after copying all the file in the folder you called 'folder' I want to execute a file inside it called 'toto' using the command "sh" how can I do this ? – wassim-azirar May 28 '12 at 23:33
@dotNET I've updated the script (above) to do that. – Fran May 29 '12 at 0:36

You must log in to answer this question.

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