Skip to content
TheChatArchiveThe Chat Archive
Amazon Novaamazon-nova-experimental-chat-05-14· AmazonHugging Face LMArena Human Preference 140K

Give me a Linux CLI command to find all TXT file in all the subdirectories of the…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with grok-3-preview-02-24’s answer.
  1. User

    Give me a Linux CLI command to find all TXT file in all the subdirectories of the current directory recursively and list them sorted by their size, the biggest last.

  2. Amazon Nova Assistant

    Certainly! You can achieve this using a combination of find, xargs, and ls commands. Here's the command to find all .txt files in all subdirectories of the current directory recursively, and list them sorted by their size, with the biggest last:

    find . -type f -name "*.txt" -print0 | xargs -0 ls -lS
    

    Let's break down the command:

    1. find . -type f -name "*.txt" -print0

      • . specifies the current directory.
      • -type f ensures that only files are considered.
      • -name "*.txt" filters the results to only include files with the .txt extension
      • -print0 prints the full file name on the standard output, followed by a null character. This option is used to handle filenames that contain newlines or other types of white space. It works with xargs -0 to ensure proper handling of such filenames.
    2. xargs -0

      • xargs builds and executes command lines from standard input.
      • -0 means input items are terminated by a null character instead of by whitespace, which works in conjunction with find -print0 to correctly handle files with spaces or newlines in their names.
    3. ls -lS

      • ls lists the files.
      • -l uses the long listing format.
      • -S sorts the files by size, largest first.

    If you only want to see the filenames and their sizes you can use:

    find . -type f -name "*.txt" -exec ls -lS {} + | awk '{print $5, $9}'
    

    In this command awk '{print $5, $9}' is used to print only the file size and the file name from the ls -lS output.

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