Pinterest Stumbleupon Whatsapp
Ads by Google

Still struggling with the Linux learning curve? We don’t blame you! It’s vastly different from Windows 7 Key Differences Between Windows & Linux You Should Know About Before Switching 7 Key Differences Between Windows & Linux You Should Know About Before Switching Read More so you’re bound to run into trouble, such as locating those files that you misplaced the other day. Is there an easy way to find them?

Fortunately, yes. However, you’ll need to be somewhat familiar with the command line A Quick Guide To Get Started With The Linux Command Line A Quick Guide To Get Started With The Linux Command Line You can do lots of amazing stuff with commands in Linux and it's really not difficult to learn. Read More in order to unlock the full power of the Linux ecosystem and all of its underlying utilities. If you haven’t already, get acquainted with these essential Linux commands An A-Z of Linux - 40 Essential Commands You Should Know An A-Z of Linux - 40 Essential Commands You Should Know Linux is the oft-ignored third wheel to Windows and Mac. Yes, over the past decade, the open source operating system has gained a lot of traction, but it’s still a far cry from being considered... Read More .

When you’re ready, here are three simple commands that you can use to locate files you just can’t seem to find.

The “Which” Command

The which command is the simplest of the three commands we’re going to explore, but this simplicity comes at a cost: its usage is extremely narrow and specific. However, for what it’s meant to do, it’s very good at what it does.

On Linux, every command that you run in the command line actually points to a binary file (also known as an executable file) somewhere on the system. When you type a command, that command’s binary file is what ends up being executed. When you use the which command with a command you’re searching for, the output is the path to that command’s binary file.

linux-find-files-which

Ads by Google

In the example above, the oft-used command sudo actually points to a binary file named sudo in the /usr/bin directory. Not all binaries are located in the this directory, though, so which comes in handy when you need to find a binary but have no idea where to start looking.

linux-find-files-whereis

An alternative command is the whereis command, which gives you a bit more information — not just the location of the command’s binary file, but the location of the command’s source files and man pages as well.

Do note that both can search for multiple commands at once by supplying as many command names as you want (as illustrated in the screenshots).

One slight difference between the two commands is that whereis will only look through a built-in list of directories when searching while which will look through all of the directories in the current user’s PATH environment variable.

The “Locate” Command

The next command we’re going to explore is locate, which uses a pre-built database of files and directories to speed up the search process. If you’ve ever used an indexed Windows search What Are the Fastest Tools for Windows Desktop Search? What Are the Fastest Tools for Windows Desktop Search? Search is one of the digital tools we take for granted and heavily rely on. Fortunately, Windows comes with a handy search feature. Could third-party tools be better and faster? We made the test. Read More , the concept should be pretty familiar.

This kind of indexed search is certainly faster than searching the entire disk drive, but the downside is that the index can sometimes fall out of sync. Though the Linux system periodically updates the index on its own, you can force it to sync using the updatedb command.

Note that an index update could take up to several minutes depending on your system’s processing power.

linux-find-files-locate

To use the locate command, all you have to do is provide a query string that it will use for finding matches. The command will output a list of all indexed directories and files that match the query.

If you want to limit the search to exact matches only, use the -b parameter. If you want to make the search query case-insensitive, use the -i parameter. If you want to limit the number of results, use the -n <#> parameter.

The “Find” Command

Lastly we have the find command, which is the most versatile of the commands we’re going to explore but also the hardest to learn because of how flexible it can be.

Do note that when you use this command, it will always search in the current directory unless specified otherwise.

linux-find-files-find-name

To find a file by its name, use the -name parameter (or the -iname parameter for case-insensitivity). Or, you could inverse the search and exclude files by their name using the -not modifier. The * symbol is used as a wildcard.

linux-find-files-find-type

You can also find all files according to their type using the -type parameter. The following common options correspond to their respective file types:

  • d: directories
  • f: regular files
  • l: symbolic links

linux-find-files-find-size

Similar to file types, you can search according to file size using the -size parameter followed by a string that indicates the size, unit, and whether we want an exact, lower than, or greater than match:

  • c: bytes
  • k: kilobytes
  • M: megabytes
  • G: gigabytes

And of course, all of these can be combined to form highly specific searches for specific files. If you want to chain multiple searches into one, use the -and and -or parameters in between queries.

Never Lose Another File on Linux

And there you have it: the best ways to find files on Linux using nothing more than the command line. No third-party software necessary. Whether you need a simple where, a fast locate, or a powerful findLinux has got you covered What's The Difference Between Linux Distributions If They're All Linux? [MakeUseOf Explains] What's The Difference Between Linux Distributions If They're All Linux? [MakeUseOf Explains] When a user is first introduced to Linux, they might be told they're using Linux, but they'll quickly learn that it's called something else. Yes, Ubuntu, Fedora, Linux Mint, Debian, openSUSE, and so many others... Read More .

How do you find files on Linux? Share your best tips and tricks with us in the comments below!

  1. flurbius
    July 4, 2016 at 5:27 pm

    Nick, While I agree with your main point I find the offensive way you communicate .. well offensive. Its made worse because of your poor grammar and spelling. Imagine if human to human communication was as pedantic as human to linux communication, you would be drowning in an ocean of 'command not found' or similar.

    Even if it was a little off topic stepan has a good point, sometimes the workflow requires a visual approach and linux is woefully lacking there. Indeed this is probably the greatest failing of linux and the main reason it has yet to 'conquer the desktop'. Despite the desktop environments you mentioned - I have yet to find one workable, simple, gui based file search mechanism. Dolphin looks good but doesn't work, many other tools don't even have a search button or menu item, Would somebody please show me a file manager that can sort files based on extension? how about album artist or any of hundreds of properties that files regularly have (but sadly can't even be displayed in linux). I do get that the command line is powerful and that linux is a better environment to do my computing in (better than apple or microsoft) but it is far from perfect.

    Another problem with linux is the culture of unhelpful snobs who are all too happy to write pages on why you shouldn't be doing what you're doing but won't write two sentences to tell you how you can actually do it.

    You shouldn't tell people to use mac or windows systems, you should listen to what they are saying and think about what you can do to make things better.

  2. Nick
    June 28, 2016 at 6:14 pm

    Do all those computer illiterate that think (in the 3rd millenium!! O_O ) that Linux is only a commend line OS?
    Read, children: No, you can use the wonderful semantic desktop capabilites in Plasma, or the old" graphical search tools in almost every common desktop for Linux. The command lines is only another more option, more efficient, faster, more handy if you are an advanced user (something that obscennely ignorants like Dan, or Stepan are not) who knows that with a few of key strokes you save time.

    So, go back to Windows or Mac, and stay ther forever, please. :)

  3. stepan wot
    November 10, 2015 at 6:15 pm

    What are those pure CLI tools doing in the third millennium? It's time for GUI, Karl!

    Catfish is a joke. It can find files, but it cannot manipulate the results. It fails to select and copy all results by drag and drop. That is pathetic.

    These tools are mostly useless without gui. How should one to sort music collection (~10K .mp3 files) in Linux?

    (1) True Linux lover
    This is a proprietary format. Thus I don't use it. Music is recorded by for profit organizations so I simply don’t listen to any.

    (2) Linux poser
    find [some_crazy_regex] # Get 500 hits. For each do
    mp3_player play --bloody-parameters /path/to/file/long_file_name.mp3
    mv /path/to/file/long_file_name.mp3 /new/path/to/file/to_triage___long_file_name.mp3

    (3) Deserter way
    Attach multimedia folder to Windows Guest and sort it using human friendly search command

    (4) Wise way
    Reboot to Windows, Sort files using GUI

    ___________________
    Is it a so called "learning curve"?
    No.
    When you learn to drive a truck you have a learning curve. When you follow an advice of a free-stuff-enthusiast (that is "just push the truck to move it - this way you save on gas") and experience difficulties ... This is called "you are doing it wrong", not "experiencing learning curve.

  4. Wild Bill
    April 24, 2015 at 12:05 pm

    Thanks for the refresher. I kinda get stuck in a rut using the same tool because of familiarity not best tool for the job.

  5. luca
    April 23, 2015 at 11:30 pm

    and don't forget to try Catfish

  6. Ivana Isadora
    March 25, 2015 at 12:46 am

    Great overview!

    I have to admit that I usually rely on GUI tools, like Searchmonkey or just the default Kfind utility in KDE, to find my files. The command-line way is so much faster, yet I can't seem to make a habit of using it. Guess I should work more on that :).

  7. Dan
    March 24, 2015 at 10:57 pm

    Gah, CLI stuff. Do you have anything with a GUI for the 21st century? In Windows 7 the Search function in the Start Menu was pretty good but slow and sometimes misses a file or two. For searches on file and folder names I use Everything (locate with a gui). I used Copernic back in XP.

    On Linux, there was Beagle. And then it was abandoned.

Leave a Reply

Your email address will not be published. Required fields are marked *