Uinix : Get the list of all files with their size and creation date, filtering for files larger than some size

Shell Scripting @ Freshers.in

Here’s a step-by-step guide on how to get the list of all files with their size and creation date, filtering for files larger than 5MB, from an EC2 instance on a specific path:

  1. Connect to your EC2 instance: Use SSH or any other remote access method to connect to your EC2 instance.
  2. Navigate to the specific path: Use the cd command to navigate to the desired folder or directory where you want to retrieve the file information.
  3. Run the command: Execute the following command to get the list of files with their size and creation date, filtering for files larger than 5MB:
    find . -type f -size +5M -exec ls -lh {} \; | awk '{print $5, $6, $7, $8, $9}'
  4. Let’s break down the command:
    • find . searches for files in the current directory and its subdirectories.
    • -type f specifies that only regular files should be considered (excluding directories and special files).
    • -size +5M filters files larger than 5MB.
    • -exec ls -lh {} \; executes the ls -lh command on each file found and prints the file size and other details.
    • awk '{print $5, $6, $7, $8}' extracts and prints the file size, creation month, day, and time.
  5. View the results: After running the command, you should see a list of files with their respective sizes and creation dates, filtered for files larger than 5MB.

{print $9} part, which prints the file name and full path. When executed, it will display the file size, creation date, file name, and full path for each file larger than 5MB.

Author: user

Leave a Reply