Language Selection

English French German Italian Portuguese Spanish

Tutorial: Using the 'find' Command

Filed under

GNU find is a powerful command-line utility that lets you search for files and folders in a hierarchical tree directory structure. It is the backend for all those utilities out there like the graphical searching in KDE or GNOME. However, find can be a little hard to handle at first by beginners. In this tutorial I will try to explain some of the capabilities of find, show some useful one-liners and provide more explanations regarding this command.

In this tutorial I will start from the basic ways of using find and head up into showing more complicated (but very useful) ways of getting the most out of it, in order to search and display exactly the results that you are looking for. The version of find that I currently have installed is 4.4.2, as it comes with Ubuntu 12.04 Precise Pangolin, and Bash 4.2.20 (older versions should work without problem too). Special thanks go to for some really great one-liners.

If you’re not familiar with the terminal, command-line or Linux in general I suggest you read my introductory tutorial here: Introduction to Linux Command-Line for Beginners.
The Basics

The simplest way of using find is by typying it in a terminal:


This will list all the files and folders (including hidden ones and their sub-files and sub-folders) in the current directory, following the whole hierarchical structure. This will usually generate a long list of files and doesn’t seem to give us much. It’s exactly the same as:

find .

Where . is the currently working directory. This will list all the files and folders in the currently working directory.

It’s probably best to use a new folder somewhere in the file system to see this in effect, a folder which doesn’t have many sub-folders and files.

Moving on, let’s search for all the files that include the name profile in their filename:

find . -name *profile*

* is a wildcard that replaces any number of characters or no character. The above command searches in the current folder for the name *profile*.

find /usr/share -name FreeSans*

This will search inside /usr/share for all the files that start with FreeSans (and end in whatever characters e.g. FreeSans.ttf). I recommend using double quotes around the pattern to search for e.g. find . -name “.bash*”.

Another example:

find /usr/share -name FreeSans* | grep Oblique

So now you know how to search for a certain filename in a specific location.

Sometimes you need to ignore uppercase and lowercase and just search for text by ignoring case-sensitive. We’ll to this just by replacing -name with -iname:

find /usr/share -iname FREESANS*


find . -mtime +3 -iname *somefile*

This will search for files that were created earlier than 3 days ago.
Get only the filename instead of whole path to the file

find will return the whole path to the files that match the search pattern, so in order to get only the filename you can use the fprintf argument command:

find /usr/bin -name "alsa*"

To get only the filename, use:

find /usr/bin -name "alsa*" -printf "%f\n"

By size

To search for files by size, use the -size argument, for example:

find /usr -size +500k -name "*png"

This will search inside /usr for files which are equal to or larger than 500 KB and are ending in png. Another example:

find /usr -size +1M -name "*png"

Which will search for files which are bigger than 1 MB in size. Instead of the plus sign, you could use minus in order to search for files that are smaller than a specified size:

find /usr -size -10c -name "*png"

The -10c specifier tells find to only display files which are smaller than 10 bytes. Don’t forget the + or – preceding the desired filesize.
Automatically list details about the found files

You could use a pipe and the xargs command for this:

find /usr/lib -size +2M -name "*.so" | xargs ls -lh

Notice that this will list the files in the current directory if find returns no file.
Searching for files than contain specific text

This is probably one of the most useful ways to search for some file which name you’ve forgot but you know some of the text it contains inside.

find . -name "*bash*" -exec grep -l "aliases" {} +

This will search in all the files that contain the patter bash for the word aliases. Those files that contain this pattern will be printed out.
Some useful one-liners

Find top 20 largest files:

find . -type f -print0 | xargs -0 du -h | sort -hr | head -20


Special thanks go to and the following articles:

More in Tux Machines

CentOS vs Ubuntu: Which one is better for a server

Finally decided to get a VPS but can’t decide which Linux distro to use? We’ve all been there. The choice may even be overwhelming, even for Linux distros, considering all the different flavors and distros that are out there. Though, the two most widely used and most popular server distros are CentOS and Ubuntu. This is the main dilemma among admins, both beginners and professionals. Having experience with both (and more) distros, we decided to do a comparison of CentOS and Ubuntu when used for a server. Read more

This Script Updates Hosts Files Using a Multi-Source Unified Block List With Whitelisting

If you ever tinker with your hosts file, you should try running this script to automatically keep the file updated with the latest known ad servers, phishing sites and other web scum.

Read more

via DMT/Linux Blog

today's leftovers

  • FLOSS Weekly 417: OpenHMD
    Fredrik Hultin is the Co-founder of the OpenHMD project (together with Jakob Bornecrantz). OpenHMD aims to provide a Free and Open Source API and drivers for immersive technology, such as head-mounted displays with built-in head tracking. The project's aim is to implement support for as many devices as possible in a portable, cross-platform package.
  • My next EP will be released as a corrupted GPT image
    Endless OS is distributed as a compressed disk image, so you just write it to disk to install it. On first boot, it resizes itself to fill the whole disk. So, to “install” it to a file we decompress the image file, then extend it to the desired length. When booting, in principle we want to loopback-mount the image file and treat that as the root device. But there’s a problem: NTFS-3G, the most mature NTFS implementation for Linux, runs in userspace using FUSE. There are some practical problems arranging for the userspace processes to survive the transition out of the initramfs, but the bigger problem is that accessing a loopback-mounted image on an NTFS partition is slow, presumably because every disk access has an extra round-trip to userspace and back. Is there some way we can avoid this performance penalty?
  • This week in GTK+ – 31
    In this last week, the master branch of GTK+ has seen 52 commits, with 10254 lines added and 9466 lines removed.
  • Digest of Fedora 25 Reviews
    Fedora 25 has been out for 2 months and it seems like a very solid release, maybe the best in the history of the distro. And feedback from the press and users has also been very positive.
  • Monday's security updates
  • What does security and USB-C have in common?
    I've decided to create yet another security analogy! You can’t tell, but I’m very excited to do this. One of my long standing complaints about security is there are basically no good analogies that make sense. We always try to talk about auto safety, or food safety, or maybe building security, how about pollution. There’s always some sort of existing real world scenario we try warp and twist in a way so we can tell a security story that makes sense. So far they’ve all failed. The analogy always starts out strong, then something happens that makes everything fall apart. I imagine a big part of this is because security is really new, but it’s also really hard to understand. It’s just not something humans are good at understanding. [...] The TL;DR is essentially the world of USB-C cables is sort of a modern day wild west. There’s no way to really tell which ones are good and which ones are bad, so there are some people who test the cables. It’s nothing official, they’re basically volunteers doing this in their free time. Their feedback is literally the only real way to decide which cables are good and which are bad. That’s sort of crazy if you think about it.
  • NuTyX 8.2.93 released
  • Linux Top 3: Parted Magic, Quirky and Ultimate Edition
    Parted Magic is a very niche Linux distribution that many users first discover when they're trying to either re-partition a drive or recover data from an older system. The new Parted Magic 2017_01_08 release is an incremental update that follows the very large 2016_10_18 update that provided 800 updates.
  • How To Use Google Translate From Commandline In Linux
  • How to debug C programs in Linux using gdb
  • Use Docker remotely on Atomic Host
  • Ubuntu isn’t the only version of Linux that can run on Windows 10
  • OpenSUSE Linux lands on Windows 10
  • How to run openSUSE Leap 42.2 or SUSE Linux Enterprise Server 12 on Windows 10

Leftovers: Software and Games