Find files by size in Linux

  sonic0002        2020-04-25 08:02:45       1,697        0    

In Linux systems, you may encounter a situation where there is no enough space on the system while you are trying to install some new packages or writing some data. In this case, you may want to clear some unneeded files. A frequent need will be find the largest files in the system so that they can be deleted first and disk space can be released quickly.

In this post, we will show a simple command to find files by size so that we know what files are taking the specified space on the system,

This command to be introduced is find. Let's say we want to find the files which are larger than 500M, we can run below command.

sudo find / -size +500M

/swap.img
/home/androidyue/file_server/ubuntu_18.04.tar
/home/androidyue/bin/TeamCity-2019.2.2.tar.gz
/proc/kcore
find: ‘/proc/23619’: No such file or directory

If want to find files with exact size, can run below.

sudo find / -size 500M

In case want to find files less than 500M, can run.

sudo find / -size -500M
/
/opt
/opt/containerd
/opt/containerd/lib
/opt/containerd/bin
/opt/gitlab
/opt/gitlab/sv
/opt/gitlab/sv/prometheus
/opt/gitlab/sv/prometheus/log
/opt/gitlab/sv/prometheus/log/run
/opt/gitlab/sv/prometheus/log/main
/opt/gitlab/sv/prometheus/log/supervise
/opt/gitlab/sv/prometheus/log/supervise/stat
/opt/gitlab/sv/prometheus/log/supervise/status
/opt/gitlab/sv/prometheus/log/supervise/pid
/opt/gitlab/sv/prometheus/log/supervise/lock
/opt/gitlab/sv/prometheus/log/supervise/ok
/opt/gitlab/sv/prometheus/log/supervise/control
/opt/gitlab/sv/prometheus/run
/opt/gitlab/sv/prometheus/env

What if want to find between 100M and 500M? Can run:

sudo find / -size -500M -size +100M
/sys/devices/pci0000:00/0000:00:02.0/resource2_wc
/sys/devices/pci0000:00/0000:00:02.0/resource2
/usr/bin/dockerd

Also there are other file size can be specified like G, k etc. The list is:

  • b – for 512-byte blocks (this is the default if no suffix is used)
  • c – for bytes
  • w – for two-byte words
  • k – for Kilobytes
  • M – for Megabytes
  • G – for Gigabytes

Reference: https://droidyue.com/blog/2020/04/20/find-files-by-size-in-linux/?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io

FILESIZE  FIND  LINUX 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

How to recover from this?