Posted: . At: 9:19 AM. This was 5 years ago. Post ID: 12964
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.


Advanced file listing tricks for Linux.


How to do various file listing tricks on Linux to find various files.

Get a listing of all files in /bin that contain the letters ‘ls’ and output the file details.

4.4 Tue Mar 05 jason@Yog-Sothoth 0: $ find /bin -type f -name '*ls*' -ls
  3933382    132 -rwxr-xr-x   1 root     root       133792 Jan 18  2018 /bin/ls
  3933380     32 -rwxr-xr-x   1 root     root        30904 Jan 18  2018 /bin/false
  3933415     32 -rwxr-xr-x   1 root     root        31928 Dec  1  2017 /bin/ntfsls
  3932325     84 -rwxr-xr-x   1 root     root        84048 Oct 16 07:29 /bin/lsblk

File size is column 7, so we can do a numerical `sort` on the 7th field in the output.

sort -n -k7

Get the 20 smallest files in the output with the head utility.

head -20

Pipe it all together:

find /bin -type f -name '*ls*' -ls | sort -n -k7 | head -20

This is the output I got with this.

4.4 Tue Mar 05 jason@Yog-Sothoth 0: $ find /bin -type f -name '*ls*' -ls | sort -n -k7 | head -20
  3933380     32 -rwxr-xr-x   1 root     root        30904 Jan 18  2018 /bin/false
  3933415     32 -rwxr-xr-x   1 root     root        31928 Dec  1  2017 /bin/ntfsls
  3932325     84 -rwxr-xr-x   1 root     root        84048 Oct 16 07:29 /bin/lsblk
  3933382    132 -rwxr-xr-x   1 root     root       133792 Jan 18  2018 /bin/ls

This example is more advanced, this will find all files that have gnome in their filename, and are under 19024 bytes in size.

4.4 Tue Mar 05 jason@Yog-Sothoth 0: $ find /usr/share/icons -size -19024c -type f -name '*gnome*' -ls | head -20
 14837143      4 -rw-r--r--   1 root     root          502 Apr 14  2018 /usr/share/icons/Adwaita/64x64/apps/gnome-power-manager-symbolic.symbolic.png
 10102182      4 -rw-r--r--   1 root     root          255 Apr 14  2018 /usr/share/icons/Adwaita/24x24/apps/gnome-power-manager-symbolic.symbolic.png
 10103956      4 -rw-r--r--   1 root     root          396 Apr 14  2018 /usr/share/icons/Adwaita/48x48/apps/gnome-power-manager-symbolic.symbolic.png
 10103284      4 -rw-r--r--   1 root     root          289 Apr 14  2018 /usr/share/icons/Adwaita/32x32/apps/gnome-power-manager-symbolic.symbolic.png
 14837619      4 -rw-r--r--   1 root     root          728 Apr 14  2018 /usr/share/icons/Adwaita/96x96/apps/gnome-power-manager-symbolic.symbolic.png
 10094571      4 -rw-r--r--   1 root     root          186 Apr 14  2018 /usr/share/icons/Adwaita/16x16/apps/gnome-power-manager-symbolic.symbolic.png
 10100275      4 -rw-r--r--   1 root     root         1373 Apr 14  2018 /usr/share/icons/Adwaita/scalable/apps/gnome-power-manager-symbolic.svg
 10226619      4 -rw-r--r--   1 root     root          436 Apr  2  2018 /usr/share/icons/HighContrast/24x24/apps/gnome-abrt.png
 10226626      4 -rw-r--r--   1 root     root          634 Apr  2  2018 /usr/share/icons/HighContrast/24x24/apps/gnome-weather.png
 10226624      4 -rw-r--r--   1 root     root          511 Apr  2  2018 /usr/share/icons/HighContrast/24x24/apps/gnome-power-manager.png
 10226620      4 -rw-r--r--   1 root     root          847 Apr  2  2018 /usr/share/icons/HighContrast/24x24/apps/gnome-aisleriot.png
 10226692      4 -rw-r--r--   1 root     root          585 Apr  2  2018 /usr/share/icons/HighContrast/24x24/apps/xchat-gnome.png
 10226623      4 -rw-r--r--   1 root     root          563 Apr  2  2018 /usr/share/icons/HighContrast/24x24/apps/gnome-nettool.png
 10226621      4 -rw-r--r--   1 root     root          626 Apr  2  2018 /usr/share/icons/HighContrast/24x24/apps/gnome-boxes.png
 10226622      4 -rw-r--r--   1 root     root          602 Apr  2  2018 /usr/share/icons/HighContrast/24x24/apps/gnome-freecell.png
 10226625      4 -rw-r--r--   1 root     root          720 Apr  2  2018 /usr/share/icons/HighContrast/24x24/apps/gnome-tweak-tool.png
 10237473      4 -rw-r--r--   1 root     root          724 Apr  2  2018 /usr/share/icons/HighContrast/48x48/apps/gnome-abrt.png
 10237480      4 -rw-r--r--   1 root     root         1185 Apr  2  2018 /usr/share/icons/HighContrast/48x48/apps/gnome-weather.png
 10237478      4 -rw-r--r--   1 root     root          746 Apr  2  2018 /usr/share/icons/HighContrast/48x48/apps/gnome-power-manager.png
 10237474      4 -rw-r--r--   1 root     root         1470 Apr  2  2018 /usr/share/icons/HighContrast/48x48/apps/gnome-aisleriot.png

This example looks for all files that are under 2 megabytes in size under the /boot folder.

4.4 Tue Mar 05 jason@Yog-Sothoth 0: $ find /boot -size -2097152c -ls | head -20
 14548993      4 drwxr-xr-x   3 root     root         4096 Mar  4 07:53 /boot
 14548994      4 drwxr-xr-x   5 root     root         4096 Mar  4 07:54 /boot/grub
 14549288      4 drwxr-xr-x   2 root     root         4096 Aug 22  2017 /boot/grub/fonts
 14549007      4 drwxr-xr-x   2 root     root         4096 Aug 23  2017 /boot/grub/locale
 14549282    120 -rw-r--r--   1 root     root       119869 Aug 23  2017 /boot/grub/locale/en@quot.mo
 14549286      8 -rw-r--r--   1 root     root         4842 Aug 23  2017 /boot/grub/locale/en_GB.mo
 14549284      4 -rw-r--r--   1 root     root         1017 Aug 23  2017 /boot/grub/locale/en_AU.mo
 14549285      4 -rw-r--r--   1 root     root          553 Aug 23  2017 /boot/grub/locale/en_CA.mo
 14549328      4 -rw-r--r--   1 root     root          712 Nov 28  2017 /boot/grub/gfxblacklist.txt
 14549005     12 drwxr-xr-x   2 root     root        12288 Aug 23  2017 /boot/grub/i386-pc
 14549001      4 -rw-r--r--   1 root     root         1208 Aug 23  2017 /boot/grub/i386-pc/hello.mod
 14549008      4 -rw-r--r--   1 root     root         1888 Aug 23  2017 /boot/grub/i386-pc/password.mod
 14549009      8 -rw-r--r--   1 root     root         7460 Aug 23  2017 /boot/grub/i386-pc/png.mod
 14549010     20 -rw-r--r--   1 root     root        19248 Aug 23  2017 /boot/grub/i386-pc/gcry_des.mod
 14549011      4 -rw-r--r--   1 root     root         2328 Aug 23  2017 /boot/grub/i386-pc/testspeed.mod
 14549277      4 -rw-r--r--   1 root     root          111 Aug 23  2017 /boot/grub/i386-pc/partmap.lst
 14549012      4 -rw-r--r--   1 root     root          708 Aug 23  2017 /boot/grub/i386-pc/setjmp.mod
 14549013     48 -rw-r--r--   1 root     root        47196 Aug 23  2017 /boot/grub/i386-pc/hwmatch.mod
 14549014      8 -rw-r--r--   1 root     root         4548 Aug 23  2017 /boot/grub/i386-pc/extcmd.mod
 14549015     12 -rw-r--r--   1 root     root         8320 Aug 23  2017 /boot/grub/i386-pc/gzio.mod

These file listing tricks should be very useful when looking for certain files and the user knows the filesize that they should be, this can be used to search for the file, if you know the filename partially, and the rough size, it can be found eventually.


Leave a Comment

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