One day, there may be a lot of files in more than one extension in the macOS, Linux or server you use, and you may be wondering about the size of these files or just want to see the size of the files with the corresponding extension for a specific study.
The other day, the server I was working on had both * .webm and * .mp4 file extensions, and I had to upgrade the server’s disk, or I would delete those with the same .mp4 extension from the same videos.
There are multiple ways to do this. I will only describe three different and most frequently used commands.
For example, if there is no hidden folder in the directory you are in, you can learn the size of .jpg files in that directory with the simplest method with the following command.
First of all, since I want to list the jpg files that exist in my directory and see one, I run the command below and display its output. Let’s check my Documents folder on my Mac, what I have.
➜ Documents ls -la | grep jpg
[email protected] 1 ercanermis staff 1607683 Feb 26 10:14 wallpaper-for-vertical-monitor.jpg
[email protected] 1 ercanermis staff 242165 Aug 19 2019 10155854826986546_245396163509039923.jpg
[email protected] 1 ercanermis staff 272199 Feb 26 10:00 C2014_Q2.jpg
Then what are the sizes of these jpg files? For the answer to the question, the following command is sufficient.
➜ Documents du -ch *.jpg
1.5M wallpaper-for-vertical-monitor.jpg
240K 10155854826986546_245396163509039923.jpg
268K C2014_Q2.jpg
2.0M total
If the total size of these files is important to you, you can do as follows;
➜ Documents du -ch *.jpg | grep total
2.0M total
Is it really 3 jpg files into my Documents folder?
I don’t think so and I decided to check what I have inside. Because I will have some hidden files or folders. Let’s check deeper what are the sizes of all jpg files?
➜ Documents find . -type f -name '*.jpg' -exec du -ch {} + | grep total
4.6M total
Hmm. Now, it says 4.6M total but previously, I mean “du -ch *.jpg | grep total” command output was 2.0M. How it possible? Because I have hidden files and folders. Let’s check them.
There you go! I forgot my git folder and I have some jpg files into it!
Conclusion
In two different ways, you learned to check the specific file extensions in a folder and list their size. You can run these commands on CentOS, ubuntu or macOS operating systems.
It will also work on different Linux distributions, such as Raspberry Pi.
For some reason, you have to extend your ec2 Linux server with our reboot and securely. In this port, you will learn how you can extend your ec2 Linux disk on aws.In this example, you will see extend the disk size from 80GiB to 120GiB.Step 1: Modify VolumeLogin to your AWS Console and find your ec2's volume (disk). Here is the tip; in the left pane, there is an Elastic Block Store > Vol...
Sometimes, maybe everybody needs to check large files in the system. There some useful commands which I'm using often.Here is the first pattern:find /home/ercan/ -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'If file size more than 25...
I'm using Amazon SSM Agent for connecting to EC2 instance via securely. Amazon SSM Agent is also able to connect to the EC2 instance console via aws.amazon.com web console. So, this is my preferred way.About a few days ago, when I tried to connect to EC2 via Amazon...
Sometimes, there may be files with more than one extension in a directory or folder. For example, .jpg, .png, .gif, .mp3, .mp4 etc. You want to download only gif files specifically from that source, but don't know how to do this? Don't be afraid, you're right.wget ...