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

Tizen News

  • New details revealed about future Samsung QLED TVs
    Samsung has unveiled the latest details of his stunning, next-generation TV. Named SUHD Qualmark Red TV, it’s based on the proprietary technology Samsung has pioneered: QLED, long for Quantum dot Light-Emitting Diode. According to sources from Samsung Electronics, the product will cover the high-end spectrum of the market, proposing itself as the top premium TV produced by the South Korean company. This move, which confirms Samsung’s continuos attention to innovation, proves the drive of the enterprise on delivering the highest quality products with consistency while maintaining a strong focus on research and development.
  • Samsung Z2 Officially Launched in Indonesia
    The Samsung Z2 launch which was initially planned for the month of September in Indonesia, however that didn’t turn out to be true. Samsung Indonesia have finally launched the Z2 in the country at an official launch event. The launch took place at the country’s capital Jakarta on Wednesday that is the 19th of October. The smartphone has been priced at 899,000 Indonesian Rupiah ($70 approx.). Samsung are also bundling a free Batik back cover with the smartphone for the early customers. This is also the first Tizen smartphone to be launched in Indonesia.
  • Game: Candy Funny for your Tizen smartphone
    Here is another puzzle type game that has recently hit the Tizen Store for you to enjoy. “Candy Funny” is brought to you by developer Julio Cesar and is very similar to Candy Crush. You have 300 levels available to play and all levels have 3 stars , the number of stars shows how good or bad you actually are. You don’t have much time to accumulate the highest score you can and unlock further screens.
  • Master Blaster T20 Cup 2016 Game for Tizen Smartphones
    Games2Win India Pvt. Ltd. ( an Indian app development company has more than 800 proprietary apps and games in all smartphone and tablet platforms. Now, they have 51 million downloads of their apps and games in all platforms. They have already got 8 games in the Tizen Store and today they added a new cricket game “Master Blaster T20 Cup 2016”.
  • Slender Man Game Series now available on Tizen Store

Red Hat and Fedora

  • Rivals Red Hat, Mirantis Announce New OpenStack Partnerships
    The cloud rivals both announce new telco alliances as competition in the cloud market heats up. Red Hat and Mirantis both announced large agreements this week that bring their respective OpenStack technologies to carrier partners. The news comes ahead of the OpenStack Summit that kicks off in Barcelona, Spain, on Oct. 24. Red Hat announced on Oct. 19 that it has a new OpenStack partnership with telco provider Ericsson. "Ericsson and Red Hat recognize that we share a common belief in using open source to transform the telecommunications industry, and we are collaborating to bring more open solutions, from OpenStack-based clouds to software-defined networking and infrastructure, to customers," Radhesh Balakrishnan, general manager of OpenStack at Red Hat, told eWEEK.
  • Turbulent Week Ends, How Did This Stock Fare: Red Hat, Inc. (NYSE:RHT)
  • Flatpak; the road to CI/CD for desktop applications?
    In this presentation I will introduce Flatpak and how it changes the software distribution model for Linux. In short it will explain the negatives of using packages, how Flatpak solves this, and how to create your own applications and distribute them for use with Flatpak. This presentation was given at the GNOME 3.22 release party, organized by the Beijing GNOME User Group.
  • The who in the where?
    The job is like many other roles called “Community Manager” or “Community Lead.” That means there is a focus on metrics and experiences. One role is to try ensure smooth forward movement of the project towards its goals. Another role is to serve as a source of information and motivation. Another role is as a liaison between the project and significant downstream and sponsoring organizations. In Fedora, this means I help the Fedora Project Leader. I try to be the yen to his yang, the zig to his zag, or the right hand to his right elbow. In all seriousness, it means that I work on a lot of the non-engineering focused areas of the Fedora Project. While Matthew has responsibility for the project as a whole I try to think about users and contributors and be mechanics of keeping the project running smoothly.

Development News

  • Eclipse Foundation Collaboration Yields Open Source Technology for Computational Science
    The gap between the computational science and open source software communities just got smaller – thanks to a collaboration among national laboratories, universities and industry.
  • PyCon India 2016
    “This is awesome!”, this was my first reaction when I boarded my first flight to Delhi. I was having trouble in finding a proper accommodation Kushal, Sayan and Chandan helped me a lot in that part, I finally got honour of bunking with Sayan , Subho and Rtnpro which I will never forget. So, I landed and directly went to JNU convention center. I met the whole Red Hat intern gang . It was fun to meet them all. I had proposed Pagure for Dev Sprint and I pulled in Vivek to do the same. The dev sprint started and there was no sign of Vivek or Saptak, Saptak is FOSSASIA contributor and Vivek contributes to Pagure with me. Finally it was my turn to talk about Pagure on stage , it was beautiful the experience and the energy. We got a lot of young and new contributors and we tried to guide them and make them send at least one PR. One of them was lucky enough to actually make a PR and it got readily merged.
  • Hack This: An Overdue Python Primer
    In writing the most recent Hack This ("Scrape the Web with Beautiful Soup") I again found myself trapped between the competing causes of blog-brevity and making sure everything is totally clear for non-programmers. It's a tough spot! Recapping every little Python (the default language of Hack This) concept is tiring for everyone, but what's the point in the first place if no one can follow what's going on? This post is then intended then as a sort of in-between edition of Hack This, covering a handful of Python features that are going to recur in pretty much every programming tutorial that we do under the Hack This name. A nice thing about Python is that it makes many things much clearer than is possible in almost any other language.
  • Why I won’t be attending Systems We Love
    Here’s one way to put it: to me, Bryan Cantrill is the opposite of another person I admire in operating systems (whom I will leave unnamed). This person makes me feel excited and welcome and safe to talk about and explore operating systems. I’ve never seen them shame or insult or put down anyone. They enthusiastically and openly talk about learning new systems concepts, even when other people think they should already know them. By doing this, they show others that it’s safe to admit that they don’t know something, which is the first step to learning new things. They are helping create the kind of culture I want in systems programming – the kind of culture promoted by Papers We Love, which Bryan cites as the inspiration for Systems We Love. By contrast, when I’m talking to Bryan I feel afraid, cautious, and fearful. Over the years I worked with Bryan, I watched him shame and insult hundreds of people, in public and in private, over email and in person, in papers and talks. Bryan is no Linus Torvalds – Bryan’s insults are usually subtle, insinuating, and beautifully phrased, whereas Linus’ insults tend towards the crude and direct. Even as you are blushing in shame from what Bryan just said about you, you are also admiring his vocabulary, cadence, and command of classical allusion. When I talked to Bryan about any topic, I felt like I was engaging in combat with a much stronger foe who only wanted to win, not help me learn. I always had the nagging fear that I probably wouldn’t even know how cleverly he had insulted me until hours later. I’m sure other people had more positive experiences with Bryan, but my experience matches that of many others. In summary, Bryan is supporting the status quo of the existing culture of systems programming, which is a culture of combat, humiliation, and domination. [...] He gaily recounts the time he gave a highly critical keynote speech at USENIX, bashfully links to a video praising him at a Papers We Love event, elegantly puts down most of the existing operating systems research community, and does it all while using the words “ancillary,” “verve,” and “quadrennial.” Once you know the underlying structure – a layer cake of vituperation and braggadocio, frosted with eloquence – you can see the same pattern in most of his writing and talks.

Android Leftovers