How to Find Files of a Particular Size In Linux

Linux system has a very power full tool called find which is used to search files and directories in linux, so this short post is intend to show how we can use find command to get files of a particular size in Linux.

`

Find File of Particular Size In Linux

You will just have to run something like:

broexperts@msrv:~$ find /home/broexperts/* -type f -size 1024k -exec ls -lh {} \;

Command Reslut:

Find files with particular size in linux
Find files with particular size in linux

Other Parameters You Can Specify With this Command For Size:

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

If you want to search bigger than some size, use (+) or smaller (–) files. For example all bigger than 512k files would be found with something like:

broexperts@msrv:~$ find /home/broexperts/* -type f -size +512k -exec ls -lh {} \;

Similar for smaller files you would use -size -512k.

Search, Copy and Delete Files From Source:

One of our reader asked Question: How can I find files with particular size from a directory and then copy them all to a an other directory for backup purpose?

Answer:

For example you have one directory called /home/broexperts/source, and now you want to find all files in this directory with size of 1M, then backup to /home/broexperts/backup, after backup you want to delete them from /home/broexperts/source Right? ok here is solution; you can use this command:

find /home/broexperts/source/* -type f -size 1M -exec mv {} /home/broexperts/backup/  \;

Warning:- This is a dangerous command, so be careful and be sure to test this command before using it on something important. In case you have duplicate filenames, you will definitely lose data during the move operations.

Similar Posts