Finding folders in linux

How To Find Files, Folders and Directories In Linux From Command Line?

Linux provides different ways to find and locate files and folders. We can use GUI tools like GNOME and KDE file managers or other 3’rd party applications designed for finding files. In this tutorial, we will look at how to find files, folders, and directories from the command line.

Tools To Find Files and Folder In Linux

As stated previously there are a lot of tools that can be used to find files and folders. We will look in detail all of them. Here list of these tools.

Find Command

find command is very featureful command used with a lot of different options. More details about find command can be found from the following tutorial.

Find Only Files

We can search only files by providing file type as -type f . We will search files those named conf in this example. We will use the glob start and end of the search term in order to accept any prefix or postfix for the search term. So this will match conffff , myconf , myconfffff , myconfiguration.txt etc.

Alternatively, we can specify the path we want to search for the given file name. We will provide the path according to . . In this example, we will search in the /etc path.

Find Only Folders

We may need only to find the folder. We will specify the type like below a directory.

Locate Command

locate command can be used as an offline database of all files and folders. locate will search a database which is created with updatedb command. More detailed information can get from the following tutorial.

As locate database only holds file and folder names we can not search in detail. But this database provides us very fast search option then find command because it works offline.

Update Database

As stated previously locate uses a database to search files and folders. Updating this database is important before a search. The update will take very little time.

Search For File or Folders

We will use locate command and the file and folder name to search.

Grep Command

grep command mainly filters given text and files contents but we can use it to find files and folders. For more detail

We can use ls command recursively and grep the files and folder we want to find. In this example, we will search for files and folders whose names contain backup .

Which Command

which command is not an actual file and folder search. which command simply search current environment executable files. This is generally useful if we are looking for a command which is not included in PATH variable and can not use automatically.

Whereis Command

whereis command is used to list given search term related binary, source, or man page files. In this example, we will search for ls binary and related man page files.

Источник

How To Find a Directory On Linux Based System

I just switched from MS-Windows server admin to Debian Linux server system administration roles. I need to find a directory called project.images. I was also told that the locate command is the simplest and quickest way to find the locations of files and directories on Linux. But the locate command is not working out for me. How do I find project.images directory using command-line options only?

Tutorial details
Difficulty level Easy
Root privileges No
Requirements find command on Linux or macOS/Unix
Est. reading time 5m

You need to use find command. It is used to locate files on Linux or Unix-like system. The locate command will search through a prebuilt database of files generated by updatedb.

The find command will search live file-system for files that match the search criteria.

How to find a directory on Linux

The find command syntax is:
find /where/to/look/up criteria action
find /dir/path/look/up criteria action
find /dir/path/look/up -name «dir-name-here»
find /dir/path/look/up -name «pattern»
find /dir/path/look/up -name «dir-name-here» -print
find /dir/path/look/up -name «dir-name-here»
find / -name «dir-name-here»
find / -type d -name «dir-name-here»
find / -type d -name «dir-name-here» 2>/dev/null

Linux find directory command

The following example will show all files in the current directory and all subdirectories:

Finding a directory

To find a directory called apt in / (root) file system, enter:

Alert: When searching / (root) file system, you need to run the find command as root user.

Dealing with “Permission denied error messages” on Linux

Find will show an error message for each directory/file on which you don’t have read permission

How to find a directory named Documents on Linux?

Type the following command to search for Documents directory in your $HOME dir:
$ find $HOME -type d -name Documents
Sample outputs:

Getting a detailed list of files/dirs

Pass the -ls to list current file in ls command output format:

How do I list only directories?

Just find directories and skip file names pass the -type d option as follows:

Replace -name option with -iname as follows:

The patterns ‘apt’ match the directory names ‘apt’, ‘APT’, ‘Apt’, ‘apT’, etc.

How do I find a directory called project.images?

Type any one of the following command:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

A note about locate command

See also
  • All find command examples from our /faq/ sections.
  • Find command man page

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

Why don’t you run updatedb and then locate and again you’ll have “simplest and quickest way to find the locations of files and directories on Linux”.

updatedb will update your database.

That only helps for semi-permanent files since it only checks periodically to update the updatedb database. For files that were created recently it will not be found.

Find is a great tool that i use a lot.
You could have talk about the -exec switch wich allows you to process the outpout. ie : find and delete all file in ./ that haven’t been modified since 90 day:

Anyway, great job on this website, keep it on!

I have to second that updatedb is the way to go for a novice linux user. No worries about syntax and whatnot. Its also very useful for when you need to do multiple scans since you only traverse the filesystem once.

In regards to -exec, you should be using -execdir when available due to some security implications… and the above rm -rf is somewhat dangerous since find by default traverses from the top down. Delete would be a much safer (and faster!!) operation than-exec rm.

I have to agree with your update, rm -Rf is maybe too dangerons to use for novice users.

I did not know -execdir wich seems to be very usefull.

Thank you for that update =)

Great article. so useful. since I don’t have root, I get very verbose “no permission” output that is useless and I have to find the actual location through all the muck. Is there a way to only print found paths? Thanks so much for this article!

All those “no permission” messages should be on stderr while the information you want is on stdout. Both stderr and stdout default to printing on the controlling terminal. Tacking “> stdoutfile” on the end of the command would separate them, leaving all the unwanted noise on the terminal and putting the good stuff in stdoutfile. It would make more sense to redirect stderr to /dev/null (throwing it away) and leaving the useful output on the controlling terminal, but that would require finding the instructions for redirecting stderr in the shell docs (again).

To avoid seeing stderr messages, just use something like this:

Источник

How to Find Files and Folders on Linux

Unless you’re a perfectionist whose files are all diligently labeled and organized, chances are you’ve had to search for a file at least once in your life. If you’re a new Linux user, you might be wondering how to find files on Linux. The good news is there are several ways to do it, which means that everyone can choose the method that suits them best.

Generally speaking, there are two types of apps that help you find files and folders on Linux. The first are those that search the live filesystem every time. The second type are apps that build an index of files, then perform searches on the index. In this article you’ll find a balanced mix of both, and you can combine them depending on your needs.

How to Find Files in the Terminal

Yes, I know…you’re not a fan of the command-line interface. That’s cool – keep reading and you’ll discover apps that are more to your liking. However, don’t think you can escape the commands. Most of the apps on this list are just graphical interfaces for find and/or locate, so you’ll still be using them, only not directly.

find

Let’s start with the most important command. Find is one of the essential Linux utilities. It looks for a string in the directories you’ve set according to parameters (“switches”) that you’ve included. This example:

find /home/username/Documents -iname “writ*” -type f

means that you’re performing a case-insensitive ( -iname ) search for files ( -type f ) in the Documents folder, and their filenames begin with “writ”. As you can see, find supports wildcards, and you can also use them to find files by their extension (for example, “*.pdf” to find all PDF files in a folder).

You can search for empty files with the -empty option, or find files by size and modification time. Find supports regular expressions, and if you want to search file contents, you can combine it with grep. To learn more, check the official documentation (or just type man find in the terminal).

locate

Locate uses a different approach. It relies on the updatedb utility which creates a database of your files and periodically updates it via cron scheduling. This lets locate know which files are currently present on your filesystem. You can also update the database manually whenever you want.

Locate can search for files by name, and you can use wildcards and regular expressions in your query. For instance:

locate -ei grub.cfg

will list the paths to all existing (-e) files called “grub.cfg”. The -i option stands for “case-insensitive”. If you don’t know the full name of the file you’re looking for, just type a part of it, and locate will display all files with the word in their name.

whereis

This command has a very specific purpose, so you probably won’t use it every day. Whereis shows you the location of the source, binaries, and user manuals for a given application. This means you won’t run whereis when you want to find a random text file. You will, however, use it when you need to check where GIMP or Firefox keep their configuration and executable files.

You can run whereis without any options to get a list of all files, or add switches for their respective functions (-b for binaries, -s for source, and -m for manuals).

How to Use a File Manager to Find Files

Most file managers for Linux can filter files by name or perform basic searches. If you don’t need any advanced parameters, this is a quick method that does the job.

Nautilus

Access the search function (highlighted in green on the screenshot) by pressing Ctrl+F or by clicking the magnifying glass icon in the toolbar. The search is case-insensitive, so you don’t have to worry about capitalizing your queries. You can filter files by type and location, although the latter is somewhat limited in terms of what you can adjust.

Dolphin

Dolphin’s search responds to the same keyboard shortcut (Ctrl+F), or you can open it from the Edit menu. It lets you filter files by name, content and location (current folder or the whole filesystem). If you have enabled file indexing with Baloo, Dolphin will be able to find files by type and modification date.

Krusader

Krusader is popular among KDE users as a Dolphin alternative thanks to its abundance of advanced options. Krusader’s file search functionality is two-fold: it works as a GUI for both find and locate commands.

The former lets you tweak many details, such as file type, included or excluded directories, size, ownership, and file permissions. Krusader can search for keywords within files and even archives (like ZIP and TAR), and you can use regular expressions to customize your query. If you’ve never tried Krusader, now is the time to give it a chance.

Thunar

Thunar integrates with the file search utility called Catfish to provide fast yet detailed results. You can filter files by type and modification date, and search file contents as well as their names. Catfish supports fuzzy (incomplete) filename matching, so you don’t have to know the exact name of the file you’re looking for.

How to Search for Files with Launchers

Launchers are usually used for, well, launching apps. However, you can also use them to find files by enabling various plugins. They’re quick and practical – you just start typing and the results pop right up. There are many launchers for Linux; we’ll focus on just a few examples.

Kupfer

Kupfer is a simple launcher available in the repositories of Debian, Ubuntu, Fedora, and Arch Linux. It comes with a bunch of plugins that let you find files with the locate command, and it can create its own catalog of indexed folders.

Kupfer is an action-based launcher. After typing in your search keyword, Kupfer will list actions that you can perform on/with the results. These depend on the plugins you’ve enabled, and you can activate them by selecting them in the drop-down menu.

KRunner

KRunner is the default KDE launcher that you can configure in the System Settings – Plasma Search dialogue.

Like Kupfer, it supports numerous plugins that help you not only find files, but also interact with other Linux applications and parts of the Plasma desktop environment. KRunner can search YouTube and Wikipedia, show your recent documents, find files by type, and much more.

Albert

Albert is inspired by the Alfred launcher for OS X. Although it looks simple, Albert has plenty of options to play with. It also has – you guessed it – plugins, with “Files” being the most important here.

This plugin lets you create an index of directories that Albert will monitor and rely on. You can enable fuzzy (incomplete) matching and choose which types of files should be indexed. To find files, simply run Albert by pressing the designated keyboard shortcut and start typing your query.

Mutate

Another Alfred-inspired launcher for Linux, Mutate doesn’t have as many options as Albert. Still, it features multiple search types, including file search. You can look for files by name and by file extension. The Preferences dialogue is somewhat unusual, because it shows which scripts Mutate is using, but doesn’t let you configure much apart from keywords and keyboard shortcuts.

Finding Files with Specialized Linux Apps

So far we’ve covered mostly simple file search solutions. They’re great for everyday lookups, but not so useful when it comes to complex queries and file contents search. If you need something more powerful, consider the following suggestions.

GNOME Search for Files

In case GNOME Search not installed on your distribution, look for the gnome-search-tool package in the repository. GNOME Search is powered by locate, find, and grep commands, and supports wildcards as well as partial filename matching. You can combine multiple search options by choosing them from the drop-down menu and clicking “Add”.

KFind

KFind is the KDE equivalent of GNOME Search with a few extra options. It can search for filenames or file contents, and if you’ve enabled file indexing on your KDE system, it can search the index to speed up the process. The options are divided into tabs, and the last tab (“Properties”) lets you find files by size, modification date, and ownership. Apart from regular expressions and wildcards, KFind supports the question mark as a stand-in for a single character in your query. For example, searching for “no?es” will find files named “noses”, “notes”, “nodes”, and so on.

Unity Dash

Ubuntu users faithful to the Unity desktop will be familiar with the Dash. Unity Dash is capable of finding your files and folders according to several parameters (filename, modification date, file type, size). To extend its functionality, you can install various Unity Scopes and Lenses. They integrate external services into Dash, enabling it to search for your browser bookmarks, Google Docs files, web history, and more.

SearchMonkey

SearchMonkey is a relatively old, but still completely functional desktop search app. Regular expressions are its main focus, and it has a “Test Regular Expression” tool that helps you build them. SearchMonkey supports all the essential search parameters (filenames, modification date, size, and file contents), plus the option to restrict the recursive search depth to a selected number of folders.

You can also save search results as a CSV file and limit the amount of results for every query.

DocFetcher

DocFetcher is a desktop search engine for people who often need to search for file contents instead of just filenames. Think researchers, students, and other users who work with large collections of text-based files. DocFetcher first builds a database of files and folders that you choose. This database is automatically updated whenever DocFetcher detects that you’ve modified the files.

When searching for files, you can filter them by type and size, or use regular expressions for fine-grained queries. DocFetcher can search within PDF, EPUB, HTML, RTF, and Office files, as well as within archive files (ZIP, TAR, 7z…) and even Outlook emails.

One great thing about DocFetcher is that it has a portable version, so you can carry your database and the app on a USB stick and use it anywhere.

Recoll

Recoll is probably the most powerful desktop search engine for Linux. It’s similar to DocFetcher: you use it to search through file contents. On first run, it will prompt you to create an index of files. You can select which directories and file types will be indexed, and limit files by size. Recoll will then set up an update schedule so that the index is always synchronized with the actual files. If you want, you can create multiple file indexes and search for files only in one, or in all of them.

You can look up files by name or search for keywords within files. Recoll lets you filter results by several criteria. It can also show related or similar files, search for phrases within files, and recognize word forms thanks to support for stemming. This means that you can search for “work”, and the results will include files that contain “working”, “worked”, “workers”…

Supported file formats include regular text files, logs, man pages, HTML, PDF, CHM, RTF, DJVU, and EPUB files, Libre and Microsoft Office files (including Excel and Powerpoint documents), TAR, RAR, 7z and ZIP archives. Note that external libraries or helper utilities might be required for some of them.

Since most file search tools support the same options, choosing one is largely a matter of convenience, or deciding what works best for your typical workflow. This list might seem long, but there are more file search utilities for Linux. We’ll mention ANGRYsearch, a new project that strives to be the fastest search tool. And what about you? Do you know any other apps for finding files on Linux? What do you use – and can you share some tips? Let us know in the comments.

Источник

Читайте также:  Windows 10 add local account
Оцените статью