Skip to content
TheChatArchiveThe Chat Archive
Mistralmagistral-medium-2506· Mistral AIHugging Face LMArena Human Preference 140K

give me a bash command that recursively lists all the files in the file tree under the…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4.1-2025-04-14’s answer.
  1. User

    give me a bash command that recursively lists all the files in the file tree under the working directory, sorts them by size, and displays the file size. if it's relatively easy, i would also like a horizontal bar that is of proportional length next to each. if it's not easy, skip that part. it's optional

  2. Mistral Assistant

    Here's a bash command that recursively lists all files in the current directory and its subdirectories, sorts them by size, displays the file size, and includes a horizontal bar proportional to the file size:

    max_size=$(find . -type f -printf "%s\n" | sort -n | tail -1); find . -type f -printf "%s %p\n" | sort -n | awk -v max_size=$max_size '{ size = $1; file = substr($0, index($0, " ") + 1); bar_length = (size / max_size) * 50; bar = ""; for (i = 0; i < bar_length; i++) { bar = bar "#"; } printf "%10d %s %s\n", size, bar, file; }'
    

    This command works as follows:

    1. find . -type f -printf "%s\n" lists all files with their sizes in bytes.
    2. sort -n sorts these sizes numerically.
    3. tail -1 gets the largest size, which is stored in max_size.
    4. find . -type f -printf "%s %p\n" lists all files with their sizes and paths.
    5. sort -n sorts this list by file size.
    6. awk processes each line to:
      • Extract the size and file path.
      • Calculate the length of the bar proportional to the file size relative to the maximum size.
      • Generate the bar using # characters.
      • Print the size, bar, and file path.

    If you're not using GNU find, you can use this alternative command which uses stat (note that stat -c is also GNU-specific):

    max_size=$(find . -type f -exec stat -c "%s" {} \; | sort -n | tail -1); find . -type f -exec stat -c "%s %n" {} \; | sort -n | awk -v max_size=$max_size '{ size = $1; file = substr($0, index($0, " ") + 1); bar_length = (size / max_size) * 50; bar = ""; for (i = 0; i < bar_length; i++) { bar = bar "#"; } printf "%10d %s %s\n", size, bar, file; }'
    

    For systems without GNU extensions, a more portable but less efficient approach would involve using ls and awk with more complex parsing, but that's beyond the scope here. The above commands should work on most Linux systems with GNU utilities.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.