Posted: . At: 10:50 AM. This was 4 years ago. Post ID: 14074
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.


How to use find on Linux to find and display a list of files.


The Linux find command is very useful for finding certain files. I will show how to search a folder and return a listing of files.

This example below shows how to list all webm and gif files in the directory and all subdirectories.

4.4 Fri Feb 21 jason@Yog-Sothoth 0: $ find -regex '.*\.\(gif\|webm\)' -print
./1397195397532.gif
./woman survival.webm
./movieclip.webm

The example above will just print the filename of each file found. But find can also exec a Linux command on each file, whether you wish to delete them, or just run ls to list more information about each file. In the example below, I am running ls -hula on each file to get more information.

4.4 Fri Feb 21 jason@Yog-Sothoth 0: $ find -regex '.*\.\(gif\|webm\)' -exec ls -hula {} \;
-rw-r--r-- 1 jason jason 2.9M Jan 22 12:13 ./1397195397532.gif
-rw-rw-r-- 1 jason jason 2.8M Feb  6 11:24 './woman survival.webm'
-rw-r--r-- 1 jason jason 358 Oct 21 20:36 ./movieclip.webm

This is another example, this is how to sort the output by filesize.

4.4 Fri Feb 21 jason@Yog-Sothoth 0: $ find -regex '.*\.\(gif\|webm\)' -exec ls -hula -S {} \;
-rw-r--r-- 1 jason jason 2.9M Jan 22 12:13 ./1397195397532.gif
-rw-rw-r-- 1 jason jason 2.8M Feb  6 11:24 './woman survival.webm'
-rw-r--r-- 1 jason jason 358 Oct 21 20:36 ./movieclip.webm

Another example, this will find all gif and jpeg files larger than 1 megabyte. This would be a very good way to find all space hogging files on your hard drive.

4.4 Fri Feb 21 jason@Yog-Sothoth 0: $ find -size +1M -regex '.*\.\(gif\|jpg\)' -exec ls -hula -S {} \;
-rw-rw-r-- 1 jason jason 2.6M Feb 19 23:54 ./1531698862242.jpg
-rw-r--r-- 1 jason jason 2.9M Jan 22 12:13 ./1397195397532.gif
-rw-rw-r-- 1 jason jason 1.3M Feb 19 23:54 ./nuuk.jpg
-rw-rw-r-- 1 jason jason 2.2M Feb 19 23:16 ./yosemite.jpg
-rw-rw-r-- 1 jason jason 2.1M Jan 22 12:13 ./1531698862235.jpg
-rw-rw-r-- 1 jason jason 1.9M Jan 22 12:13 ./1531698862236.jpg
-rw-rw-r-- 1 jason jason 1.8M Feb  4 10:25 ./1531698862237.jpg
-rw-rw-r-- 1 jason jason 2.2M Jan 22 12:13 ./1531698862211.jpg
-rw-rw-r-- 1 jason jason 2.6M Jan 22 12:13 ./1531698862219.jpg
-rw-rw-r-- 1 jason jason 4.5M Jan 22 12:13 ./1531698862229.jpg
-rw-rw-r-- 1 jason jason 1.7M Feb 19 23:16 ./zqpdeq9hmph41.jpg
-rw-rw-r-- 1 jason jason 2.6M Jan 22 12:13 ./1531698862215.jpg
-rw-rw-r-- 1 jason jason 2.2M Jan 22 12:13 ./thangka.jpg

This is another way to list the owner of the files, the file-size in bytes and the filename.

4.4 Fri Feb 21 jason@Yog-Sothoth 0: $ find -size +1M -regex '.*\.\(gif\|jpg\)' -exec stat -c "%U %s, %n" {} \;
jason 2658258, ./1531698862242.jpg
jason 3030926, ./1397195397532.gif
jason 1332476, ./nuuk.jpg
jason 2245097, ./yosemite.jpg
jason 2134184, ./1531698862235.jpg
jason 1976917, ./1531698862236.jpg
jason 1805314, ./1531698862237.jpg
jason 2227395, ./1531698862211.jpg
jason 2623887, ./1531698862219.jpg
jason 4662743, ./1531698862229.jpg
jason 1688003, ./zqpdeq9hmph41.jpg
jason 2623887, ./1531698862215.jpg
jason 2227886, ./thangka.jpg

The stat utility is very useful for returning filesystem and file information.

To find all space hogging files in your home directory, use this command.

4.4 Fri Feb 21 jason@Yog-Sothoth 0: $ find -size +1G -regex '.*\.\(iso\|rar|zip\)' -exec stat -c "%U %s, %n" {} \;
find: ‘./.cache/dconf’: Permission denied
jason 3939235840, ./Documents/en_windows_10_enterprise_x64_dvd_6851151.iso
jason 5421459456, ./Downloads/Win10_1909_English_x64.iso
jason 2763894784, ./Downloads/kali-linux-2019-4-amd64-iso/kali-linux-2019.4-amd64.iso
jason 2545156096, ./Downloads/focal-desktop-amd64.iso
find: ‘./.gconf/desktop/gnome/url-handlers’: Permission denied
find: ‘./.dbus’: Permission denied

This is very useful if you download a lot of files and you need to clear some space.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.