How to list all files in a directory that are larger than one megabyte.

Posted: September 15, 2014. At: 1:16 PM. This was 3 years ago. Post ID: 7732
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

Use this command to find all files in a directory that are larger than 1 megabyte.

find . -maxdepth 1 -type f -size +1M -exec ls -Shal {} \+ | head

Here is this command in practice. This is a very useful command.

ubuntu@ip-172-31-20-234:/boot$ find . -maxdepth 1 -type f -size +1M -exec ls -Shal {} \+ | head
-rw-r--r-- 1 root root 7.4M Sep 10 04:05 ./initrd.img-3.13.0-29-generic
-rw------- 1 root root 5.6M Jun  4 21:57 ./vmlinuz-3.13.0-29-generic
-rw------- 1 root root 3.3M Jun  4 21:57 ./System.map-3.13.0-29-generic
-rw-r--r-- 1 root root 1.2M Jun  4 21:57 ./abi-3.13.0-29-generic
<pre>
 
This command shows how to list all files that are larger than 1024 kilobytes.
 
<pre lang="bash">
find . -maxdepth 1 -type f -size +1024k -exec ls -Shal {} \+ | head

Again, here is this command in action.

ubuntu@ip-172-31-20-234:/boot$ find . -maxdepth 1 -type f -size +1024k -exec ls -Shal {} \+ | head
-rw-r--r-- 1 root root 7.4M Sep 10 04:05 ./initrd.img-3.13.0-29-generic
-rw------- 1 root root 5.6M Jun  4 21:57 ./vmlinuz-3.13.0-29-generic
-rw------- 1 root root 3.3M Jun  4 21:57 ./System.map-3.13.0-29-generic
-rw-r--r-- 1 root root 1.2M Jun  4 21:57 ./abi-3.13.0-29-generic

Here I am listing all files larger than 3 kilobytes.

ubuntu@ip-172-31-20-234:~/easy-rsa$ find . -maxdepth 1 -type f -size +3k -exec ls -Shal {} \+ | head
-rwxr-xr-x 1 ubuntu ubuntu  13K Sep 14 22:53 ./pkitool
-rw-r--r-- 1 ubuntu ubuntu 8.3K Sep 14 22:53 ./openssl-0.9.8.cnf
-rw-r--r-- 1 ubuntu ubuntu 8.2K Sep 14 22:53 ./openssl-1.0.0.cnf
-rw-r--r-- 1 ubuntu ubuntu 7.7K Sep 14 22:53 ./openssl-0.9.6.cnf

This is a very useful Linux tip. You can easily list all files larger than a certain size without any problems. This is very good for finding space hogs in a directory.

No comments have been made. Use this form to start the conversation :)

Leave a Reply