How to Find Files and Directories in Linux
Just follow the steps below
Just installed anew Linux distro? You might wonder how to find files and directories on your new system.
There are a few different ways you can find files and directories on a Linux PC. You can use Linux commands via the terminal, such asfind, to help you. Alternatively, you can use the built-in file management tool provided by your Linux distro.
If you want to find files and directories on Linux, follow the steps below.
Using the Find Command
Thefindcommandis one of the most powerful and versatile tools for finding files and directories by name in Linux. It can search your folders for various criteria, such as the filename, owner, file permissions, file type, size, or date.
Find can also perform actions on the matched files, such as deleting, moving, or executing commands on them. The basic syntax of the find command is:
find [options] [path] [expression]
Optionscontrols how the command behaves,pathspecifies the starting directory or directories to search, whileexpressionconsists of additional options or actions that you can use (separated by operators).
For example, to find all files with the .txt extension in the current directory and its subdirectories, you can use this command:
find . -type f -name “*.txt”
The dot (.) after find indicates the current directory. The-type foption specifies that you’re searching for regular files. The-name “*.txt”option matches files that end with .txt.
You can also use the-inameoption instead of-nameif you want to perform a case-insensitive search. For example:
find . -type f -iname “*.txt”
This will match files that end with .txt, .TXT, .Txt, etc.
The find command has a number of useful features and settings that you can explore by reading its manual page via the terminal (man find). Some of the most useful ones are:
Using the Locate Command
Thelocatecommand is another way to find files and directories in Linux. Locate is faster than thefindcommand because it uses a previously built database of file names and locations. However, it may not be as up-to-date as the find command because the database is updated periodically by a cron job.
The basic syntax of the locate command is:
locate [options] pattern
Thepatternis a string of characters that you want to search for in the file names. The locate command will return all file names that contain the pattern as a substring.
For example, to find all files that contain the word “yes” in their names, you can use this command:locate yes.
If you’ve recently updated a large number of files and you want to update the database manually before using the locate command, you can run this command via the terminal:
sudo updatedb
You may need to enter your password to run the command.
Like find, you can check for additional options for locate using the manual page via the terminal (man locate). These include:
Using the GUI File Management App
If you prefer a graphical interface for finding files and directories in Linux, you can use the file management app that’s included with your Linux distribution. This might be calledNautilus,Files, orFile Manager, depending on whether you’reusing Ubuntuor another Linux distribution.
These apps allow you to browse and search your files and directories using a familiar window-based interface. You can navigate through your file system using the sidebar, toolbar, or breadcrumbs. You can also use keyboard shortcuts or drag-and-drop to perform various actions on your files and directories.
To search for files and directories using the common file app, you can use the search box in the toolbar or pressCtrl+F. This will open a search panel where you can enter your search criteria.
You’ll also be able to filter the results by type, size, or date. In Files on Ubuntu, press thedownwards arrownext to the search results to choose your search criteria.
Your file management app will display all of the matching files and directories in the main area. You can then double-click on any file or directory to open it or perform other actions on it using the right-click menu, as long as you have thenecessary file permissions.
Managing Files on Linux
Finding files and directories in Linux can be a daunting task for beginners. By using the find and locate Linux commands, or by using your Linux system’s file management tool, you can search for files and directories by various criteria and perform actions on them. For instance, you candelete files on your Linux PCthat you don’t need.
Another task you could try isrenaming your files and folders on Linuxto make it easier to locate your most important files.
Ben Stockton is a freelance technology writer based in the United Kingdom. In a past life, Ben was a college lecturer in the UK, training teens and adults. Since leaving the classroom, Ben has taken his teaching experience and applied it to writing tech how-to guides and tutorials, specialising in Linux, Windows, and Android. He has a degree in History and a postgraduate qualification in Computing.Read Ben’s Full Bio
Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.
HomeAbout UsEditorial StandardsContact UsTerms of Use
Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved