How to find all .zip files and file size in linux?

by georgiana.senger , in category: General Help , 7 months ago

How to find all .zip files and file size in linux?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by viola_gleichner , 7 months ago

@georgiana.senger 

To find all .zip files and their file sizes in Linux, you can use the find command along with the ls command and some basic shell scripting.


Here is the command to achieve this:

1
find /path/to/search -type f -name "*.zip" -exec ls -lhS {} ; | awk '{print $5, $9}'


Replace /path/to/search with the directory where you want to search for the .zip files. This command will recursively search for .zip files in the specified directory.


Let's break down the command:

  1. find: Locates files based on various search criteria.
  2. /path/to/search: The directory path where you want to search for .zip files.
  3. -type f: Only search for regular files (excluding directories and other special files).
  4. -name "*.zip": Search for files with a .zip extension.
  5. -exec ls -lhS {} ;: Executes the ls command with the -lhS options on each file found, which displays the file size in a human-readable format and sorts files based on their size in descending order.
  6. awk '{print $5, $9}': Uses awk command to print the file size (5th field) and file name (9th field) from the ls command's output.


After running this command, you will get a list of .zip files with their respective file sizes.

Member

by johann , 2 months ago

@georgiana.senger 

To find all .zip files and their file sizes in Linux, you can use the du command with the find command. Below is the command to achieve this:

1
find /path/to/search -type f -name "*.zip" -exec du -h {} ;


Replace /path/to/search with the directory where you want to search for the .zip files. This command will recursively search for .zip files in the specified directory.


When you run this command, you will get a list of .zip files along with their file sizes in a human-readable format.


Here's a breakdown of the command:

  • find: Locates files based on various search criteria.
  • /path/to/search: The directory path where you want to search for .zip files.
  • -type f: Only search for regular files (excluding directories and other special files).
  • -name "*.zip": Search for files with a .zip extension.
  • -exec du -h {} ;: Executes the du command with the -h option (human-readable format) on each file found.


After running this command, you will see a list of .zip files in the specified directory along with their respective file sizes.